I want to know the General formula for Writing Regula开发者_JS百科r Expression? Any article?
Regexes for email addresses are trickier than you'd think. Here's a good page to start: http://www.regular-expressions.info/email.html
A "complete" regex here: http://code.iamcal.com/php/rfc822/full_regexp.txt ;)
There isn't really a general formula. Regex is a non-trivial language for matching strings. There are plenty of books and tutorials available.
One of the better ways of learning regex is to use a piece of regex designer software, like this one.
Regexes for emails are tricky, but there are some good ones here: http://regexlib.com/DisplayPatterns.aspx
Yes, start with the Regex class. And read lots of tutorials, like this one.
in .vb if you dont care about a postback....
Imports System.Text.RegularExpressions
valueStr = Regex.Replace(oldString, ",", ",@")
Another common way to do it is in javascript in your aspx page without a postback.
script type = "text/javascript"
function intChecker(field) {
//use regular expressions to take out alphanumeric characters
//and special characters such as !@#$
//The reason I run the match before I run the replace is so that the
//cursor doesn't jump to the end of the textbox unless it is a bad character
var regExp2 = /[A-Za-z\.\!\@\#\$\%\^\&\*\(\)\,\?\:\;\_\-\+\=\~\/]/g;
if (field.value.match(regExp2)) {
field.value = field.value.replace(regExp2, '');
}
}
/script
This will get you started with regex in vb. You will need to find the expression to validate the email address. Have fun!
精彩评论