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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.