I am working on a java script based application where I need to validate the username text box then what are all the symbols I should avoid in order to block cross side scripting using REGEX
Asked
Active
Viewed 50 times
-2
-
Did you try anything so far? – Rambler Jun 24 '16 at 05:48
1 Answers
0
For just a username you should maybe accept only alphanumeric chars, something like:
~^[a-z0-9_.-]+$~i
[EDIT] to add explanations:
~
: delimiter but in JS you will need/
to delimit insteadi
: case insensitive flag^
: match beginning of string$
: match end of string[]
: match characters in between those bracketsa-z
: is a to z range0-9
: 0 to 9 range_.-
: also accepts those chars+
: is to allow this pattern 1 or more times

antoni
- 5,001
- 1
- 35
- 44