javascript - Regex for required field? - Stack Overflow

i need a regular expression that checks if the multiline textbox has been left emtpy. It should match o

i need a regular expression that checks if the multiline textbox has been left emtpy. It should match on anything except whitespace. Im using ASP.NET.

I know i could use a Required Field Validator, but this will not allow me to run a custom javascript script on failed validation.

Thanks

i need a regular expression that checks if the multiline textbox has been left emtpy. It should match on anything except whitespace. Im using ASP.NET.

I know i could use a Required Field Validator, but this will not allow me to run a custom javascript script on failed validation.

Thanks

Share Improve this question asked Oct 30, 2011 at 16:47 TheGateKeeperTheGateKeeper 4,53023 gold badges68 silver badges105 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

Use the \S predefined set. it will match anything that is not whitespace.

var text = textBox.value;
text = text.replace(/^\s*/,'').replace(/\s*$/,''); // trimming
if(text){
  // run your code here
}

Maybe you can use a CustomValidator, as RegularExpressionValidator doesn't support empty strings. But you must define ValidateEmptyText=true

try this:

^[\s\t\r\n]*\S+

test => http://jsfiddle/KFCHM/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745036710a4607563.html

相关推荐

  • javascript - Regex for required field? - Stack Overflow

    i need a regular expression that checks if the multiline textbox has been left emtpy. It should match o

    9小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信