jquery - Javascript regex .test() "Uncaught TypeError: undefined is not a function" -
just trying use javascript's regex capabilities .test()
function.
var nameregex = '/^[a-za-z0-9_]{6,20}$/'; if(nameregex.test($('#username').val())) { ... }
the error on line if(nameregex.test($('#username').val())) {
debugger breaks there , says "uncaught typeerror: undefined not function". seems .test()
not defined? shouldn't be?
as stands, nameregex
isn't regex string , string
doesn't have test
functon why getting error.
remove quotes around regex. literal form of regex.
var nameregex = /^[a-za-z0-9_]{6,20}$/; //remove quotes
Comments
Post a Comment