- 1. bool istrue = Regex.IsMatch(email, @"^\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,10})\s*$");
- if (!istrue)
- {
- this.lab_email.InnerHtml = " 邮箱格式错误 请修改";
- return false;
- }
- 2.string email = this.eamilTextbox.Text.Trim();
- string pattern = @"[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})";
- if (!Regex.IsMatch(email, pattern))
- {
- this.eamilTextbox.Focus();
- return false;
- }
- JS:
- var re = /^\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,10})\s*$/; //邮箱格式
- if (!re.test(Email))
- {
- document.getElementById('lab_email').innerHTML=' 邮件格式错误';
- }
复制代码 |