开发者

regular expression for special characters

I am using this regular expression for validating email address for exampl开发者_运维百科e:

ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

and now I want to write a validation expression for not using one special character, like ";" in my example...

P.S. I know how to do this in JavaScript with the keyCode function for example, but I need it as a simple regular expression...


I'm guessing that you're looking for an entirely new regex that has nothing to do with your email regex, and that the only rule for this regex is: "Match any string that does not contain a semicolon."

This is easy. Use the following regex:

^[^;]*$

Explanation:

^ matches the start of the string.

[^;]* is a negated character class. As the first character inside brackets, the ^ takes on a new meaning as "anything but". So this expression means "Match a character unless it's a semicolon". The * allows any number of repetitions, including zero.

$ matches the end of the string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜