Regex Issue, Restricting '*' Character
I have a text area, where I am allowing only a-z characters and number, with some special characters (like (, ), \, _). My regex looks like: /[^a-zA-Z0-9()-\/\\_ ]/g and my javasc
Solution 1:
You need to escape the -
in the regexp:
/[^a-zA-Z0-9()\-\/\\_ ]/
Otherwise, you're matching all the characters between )
and /
: *
+
,
-
.
See the ASCII Table to see what characters are in a range.
Solution 2:
Use this regex
to to include *
also in your search:
[^a-zA-Z0-9()\-\/\\_ ]{0,1}[*]
Solution 3:
Try this:
functioncheckValue (eleValue) {
var re = newRegExp(/[a-z0-9\(\)\/\\_\s]+/ig);
return re.test(eleValue);
}
Post a Comment for "Regex Issue, Restricting '*' Character"