Jump to content

Easy String Vaildation


duckstar

Recommended Posts

Hi,

 

This is going to be a very easy question for someone to answer.

 

This code is for AlphaNumberic

function isAlphaNumeric(val)
{
if (val.match(/^[a-zA-Z0-9]+$/))
{
return true;
}
else
{
return false;
} 
}

 

I want it to do exactly the same, but to also allow the forwards slash "/"

Is this possible ?  I am not sure how to add it to (/^[a-zA-Z0-9]+$/)  since i have no idea what is going on there.

 

Thanks

Duckstar

Link to comment
https://forums.phpfreaks.com/topic/198512-easy-string-vaildation/
Share on other sites

/^[a-z\d/]+$/i

 

^ = matching the beginning of the line or string

[a-z\d/] = character set matching any letters from a-z, any digit (\d) or a forward slash (/)

+ = matches the previous expression one or more time

$ = matches the end of the line or string

i = regular expression modifier meaning case-insensitive

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.