Skip to content Skip to sidebar Skip to footer

Javascript - Regular Expression That Validates One +/- At Begning And One Decimal Point

I'm trying to write a regular expression that can validate one +/- at begning, and one decimal point in the string using test() object method. Currently my regex is : /[\d\b\t\+\

Solution 1:

Basic regular expression

/^[+-]\d+\.\d+$/

Explanation:

^     Match start of string
[+-]  Match either plus or minus
\d+   Match one or more numbers of digits
\.    Match a period, the \ escapes it since it means any character
\d+   Match one or more numbers of digits 
$     Match end of string

Post a Comment for "Javascript - Regular Expression That Validates One +/- At Begning And One Decimal Point"