Link to home
Start Free TrialLog in
Avatar of Swaragh 013
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
Avatar of ozo
ozo
Flag of United States of America image

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:
^(na|NA|\d+(\.\d*)?)$

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Swaragh 013
Swaragh 013

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial