Arihant Arihant - 7 days ago 5
Javascript Question

How to include whitespaces in .match() javascript

I have the following code to check for standard characters:

if(modelName.match(/^[0-9a-zA-Z]{1,40}$/)){
//safe
}
else{
//not so safe
}


How can I add whitespaces to the match criteria?

Answer
if(modelName.match(/^[0-9a-zA-Z ]{1,40}$/)){

or

if(modelName.match(/^[0-9a-zA-Z\s]{1,40}$/)){
Comments