Regular expression problem [closed]
Expression should start with a alphanumeric and should have alphabets, @
, $
, %
, _
, -
and a single space in the middle and should ends with alphanumeric.
E.g.
1a1 -- valid
1111 -- invalid
2222$2211 -- valid
%11a25 -- invalid
This will match one or more alphanumeric characters, followed by any alphabetic characters plus the extra characters, followed by one or more alphanumeric characters.
/^[a-z\d]+[a-z @$%_-][a-z\d]+$/i
jsFiddle.
The fiddle validates the same as your test data.
You should learn about regular expressions.
I think what Akhilesh wants is this regexp:
/^[a-z0-9][a-z@$%_ -]+[a-z0-9]$/i
Edit: Hmm, it matches the description, but not the examples Akhilesh gave. The example "2222$2211" doensn't match his/her description.
精彩评论