Skip to content Skip to sidebar Skip to footer

Regexpression.test

var regExpression = /^([a-zA-Z0-9_\-\.]+)$/; //line 2 //// var regExpression = '/' + '^([a-zA-Z0-9_\-\.]+)$' + '/'; //line 3 alert (regExpression.test('11aa')); The above code is

Solution 1:

Line 3 sets regExpression to a string. Strings does not have a test method. You need to turn the string into a RegExp.

var regExpression = newRegExp("^([a-zA-Z0-9_\\-\\.]+)$");

Omit the slashes, as they are not part of the regexp itself.

Solution 2:

Post a Comment for "Regexpression.test"