HI All I am using regex for not allowing special characters
I want to allow \\ / * ? % | : , ( ) - _ ; # . + characters only. Its working fine for all except <>.
Can any one help me with this. May be I am doing some mistake in my code.
Thanks here is my code:
public validate(val: any) {
let regExp = /^[ \\/*?%|()-_;#.+:, a-zA-Z0-9]+$/;
//if (!val.match(regExp) || val.length < 1)
if (!regExp.test(val) || val.length < 1)
return false;
else
return true;
}
With the escaping of the -
as mentioned in the comment by @georg on your question, it would be:
let regExp = /^[ \\/*?%|()\-_;#.+:, a-zA-Z0-9]+$/;
Apparently, you may need to also escape the /
character inside:
let regExp = /^[ \\\/*?%|()\-_;#.+:, a-zA-Z0-9]+$/;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.