Swaragh 013
asked on
Regular expression to allow decimal or text
Please suggest me regular expression to allow all decimal number or text such as "na" OR "NA"
like
4.4 correct
0.5 correct
6 correct
te WRONG
na correct
NA correct
like
4.4 correct
0.5 correct
6 correct
te WRONG
na correct
NA correct
na|NA|\d+(\.\d*)?
Please note that @ozo's pattern will still match a substring of the string you're testing, so that values like te4.4 or tena will match. Depending on the circumstances, this may or may not matter.
If you're validating a form field, it probably does matter, in which case you'll probably want something like:
If you're validating a form field, it probably does matter, in which case you'll probably want something like:
^(na|NA|\d+(\.\d*)?)$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.