$value = 077283331111333;
if( ! preg_match(/^[0-9]{1,20}+$/, $value))
{
echo $value . " is not a number that has between 1,20 digits";
}
I’m trying to turn this Php conditional statement into a Javascript one.
This is what I have, currently not working.
var value = 077283331111333;
var regex = '/^[0-9]{1,20}+$/';
var match = regex.test(value);
if ( ! match) {
console.log(value + 'is not a number that has between 1,20 digits');
}
And this is the error I’m getting.
Object /^[1,0]{1}+$//^[0-9]{1,20}+$/ has no method ‘test’
Any ideas? Additionally this within a node.js environment.
That method is undefined because that’s not a regex but a string.
You need to drop the quotes in order to create a
RegExpobject in javascript:Anyway I don’t think that’s a valid regex (because of the double slashes) you might wanna check for typos there…
A regex to check for a number between 1 and 20 digits is just: