Regular expressions
-
I am trying to test a text box for either numbers or a null entry. I have tried using [0-9]|[:blank:]|[:space:] but it will not work. Any help would be appreciated.
[0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006
-
[0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006
-
[0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006
Just a note: I've had some issues using \d on some regex interpreters. If you run into problems with it, use
[0-1]*
(or+
, depending on your purposes). Michael Flanakin Web Log -
I am trying to test a text box for either numbers or a null entry. I have tried using [0-9]|[:blank:]|[:space:] but it will not work. Any help would be appreciated.
if you are using regularexpressionvalidator control, this control doesn't check against your regex if it's empty. This behavior works ok for you, you would only need to add the validation of space to your reg expression. daniero