Jump to content

Javascript Regex help


adam84

Recommended Posts

The whole string must be that, or part of the string?

part of string:

\[a-zA-Z0-9_\.\-]+\

 

the whole string:

\^[a-zA-Z0-9_\.\-]+$\m

http://is.gd/Tyt

 

why the subgroup?

it looks fine, its probably something else that is causing your problems. You should have posted some problem code.  ;)

function validString(string)
{
    var invalidChars = new RegExp(/[^\w ]/);
    return !invalidChars.test(string);
}

 

It's easier to check for invalid characters than to test for valid characters.

 

\w = Match any alphanumeric character including the underscore. Equivalent to [a-zA-Z0-9_].

 

So using that and adding a space check for any character that is not in the approved "white" list.

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.