Is the following correct?
var z1=^[0-9]*\d$;
{
if(!z1.test(enrol))
{
alert('Please provide a valid Enrollment Number');
return false;
}
}
Its not currently working on my system.
You can test it as:
/^\d*$/.test(value)
Where:
/ at both ends mark the start and end of the regex^ and $ at the ends is to check the full string than for partial matches\d* looks for multiple occurrences of number charctersYou do not need to check for both \d as well as [0-9] as they both do the same - i.e. match numbers.
var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/
var isNumber = function(s) {
return numberRegex.test(s);
};
"0" => true
"3." => true
".1" => true
" 0.1 " => true
" -90e3 " => true
"2e10" => true
" 6e-1" => true
"53.5e93" => true
"abc" => false
"1 a" => false
" 1e" => false
"e3" => false
" 99e2.5 " => false
" --6 " => false
"-+3" => false
"95a54e53" => false
^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)?\s*$ if you don't require the scientific notation support.
/^[0-9]*\d$/. You could also use/^\d+$/. Note that if the test passes, it just means its all digits, it isn't necessarily a valid enrolment number.