Coding & Programming > JavaScript Forum

Regular Expressions

(1/1)

Alex:
how can I test if a user typed a number or a boolean value using RegEx?

The number can be ANY number;
The boolean value should be 'true' or 'false' (lowercase);
Also need a sample for boolean value 'true' or 'false' (lowercase OR uppercase);

Nicpoint45:
For number, use

/\d+/g

Regular expression must be used on string and cannot be used on boolean value.

tradedemon:
I'd use something like this

/(true|false|[0-9]*)/



Navigation

[0] Message Index

Go to full version