Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,
Wanted some help with inserting values in a text box with javascript validation wherein it should insert letters, numbers and certain special characters like
(\ -) only.
What I used to do is var re = /^[a-zA-Z0-9]+$/; for the text box
which inserts letters and numbers.
and thought var re = /^[a-zA-Z\0-9-].+$/;would work but instead
it takes all special characters.Also tried using
var re = /^[a-zA-Z\0-9-].+$/; and var re = /^[a-z,A-Z,0-9,\-,\\\\]*$/; these two exp inserts alphanumeric and - characters but does not insert \. \ is a metacharacters itself hence also have tried using \\ but even this does not work. In exps var re = /^[a-zA-Z\0-9-].+$/; or var re = /^[a-z,A-Z,0-9,\-,\\\\]*$/; I just want is an added \ along with alphanumerics chars and -.
Thank You.
Posted

1 solution

just one dot solved my query,
var re = /^[a-z,A-Z,0-9,\-,\\\\.,\/]*$/;
adding a '.' after \\\\ insert a '\' and \/ adds a '/'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900