I’m using the match
function with a Regular Expression.
The code I’m using is:
if(val.match(/^s+$/) || val == "" )
However, it produces the following error:
"val.match is not function"
What is the problem?
I would say that val
is not a string.
I get the
val.match is not function
error for the following
var val=12; if(val.match(/^s+$/) || val == ""){ document.write("success: " + val); }
The error goes away if you explicitly convert to a string String(val)
var val=12; if(String(val).match(/^s+$/) || val == ""){ document.write("success: " + val); }
And if you do use a string you don't need to do the conversion
var val="sss"; if(val.match(/^s+$/) || val == ""){ document.write("success: " + val); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With