开发者

Regular expression problem [closed]

开发者 https://www.devze.com 2023-03-08 06:42 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the开发者_高级运维 help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消