Can anyone help me with a javascript regular expression that satisfies the following conditions (it is to validate input in textarea):
- there should be minimum 3 characters
- the first character is always /
- the entire input string shouldnot match the exact string '/abc' and '/xyz' but it can be anyother like /abce or /abct etc...
Ex: the input such as /xyzw, /ab, /abcd, /asdad are accepted and such as /a, /abc etc. are not accepted
Can anyone help me with a javascript regular expression that satisfies the following conditions (it is to validate input in textarea):
- there should be minimum 3 characters
- the first character is always /
- the entire input string shouldnot match the exact string '/abc' and '/xyz' but it can be anyother like /abce or /abct etc...
Ex: the input such as /xyzw, /ab, /abcd, /asdad are accepted and such as /a, /abc etc. are not accepted
Share Improve this question edited Feb 28, 2012 at 11:37 Pradeep asked Feb 20, 2012 at 14:17 PradeepPradeep 991 gold badge4 silver badges15 bronze badges 2-
/^\/(?!abc$|xyz$)[\S\s]{2,}/
– Rob W Commented Feb 20, 2012 at 14:19 -
1
Your condition 3 needs clarification. It can't match
/xyz
but then later that is ok? – YXD Commented Feb 20, 2012 at 14:20
1 Answer
Reset to default 7/^\/(?!abc$|xyz$)[\S\s]{2,}/
Meaning:
/
^ Start of string
\/ "/"
(?!abc$|xyz$) Not followed by only abc or xyz ($ = end of string)
[\S\s]{2,} At least two characters.
/