×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Used to validate email address

本文发表在 rolia.net 枫下论坛/\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i

This is saying that for example an email address:
FIRST@SECOND.com


The regular express is saying that we allow minimum of 2 letters or numbers in the FIRST. Then follow by @. Then the second portion contains at least 3 letters or numbers, or "-", or "_". And the second portion can be repeated maximum of twice with the dot (eg. Hua@server.microsoft.com is accepted, but hua@server1.server2.microsoft.com is not). The follow by a dot. Then the COM portion can be ONLY letters (no numeric or other characters) and it can only be 2 to 3 letters.

eg. The following input won't be accepted.
thisthatthisthat@hotmail (no .?? component)
t@hotmail.com (only 1 letter before@)
this@hotmail.comm (4 letters at the end, max can be only 3)
this@hotmail.c (1 letter at the end, min is 1)
this.that@hotmail.com (the first part cannot have dot)
this.that@ser.server1.hotmail.com (too complex at the end)
thisthat (no @)



All langugages have regular expression and you should use this to validate inputs.

In javascript:
var temp = trim(tt.email.value)
var pattern = /\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i
if (pattern.exec(temp) == null) {
alert("You have to enter a valid email address")
tt.email.focus();
return false;
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / VB.NET,如何限制一个textbox里面只能输入3位的数字而不能是字符啊?限制长度好办,关键是如何判断输入的是000-999的数字呢?
    • 使用IF isNumeric来validation
      • 谢谢。刚想了一个苯办法,判断字符值是否在“000”和“999”之间好像也可以。再试试你告诉我的方法。
        • 我喜欢用JAVASCRIPT直接在页面上做VALIDATION。
          • 用vb.net也可以吗?好像只有作网页的时候才可以用JS来validate吧?
            • 可以的。
      • 试验可用,谢谢。一个新问题,如何判断输入的数字小于3位呢?因为要求必须是3位的数字。谢谢先。
        • Use regular expression to validate.
          • 搞定,直接判断输入字符长度就可以了。呵呵,好久不写code了,都快忘光了。谢谢以上各位。
            • If you learn regular expression, you can validate any type of entries in only one single step. Here, you have to validate the length, then the value... It's not efficient.
              • 没学过。能不能举个例子用regular expression来validation啊?
                • Used to validate email address
                  本文发表在 rolia.net 枫下论坛/\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i

                  This is saying that for example an email address:
                  FIRST@SECOND.com


                  The regular express is saying that we allow minimum of 2 letters or numbers in the FIRST. Then follow by @. Then the second portion contains at least 3 letters or numbers, or "-", or "_". And the second portion can be repeated maximum of twice with the dot (eg. Hua@server.microsoft.com is accepted, but hua@server1.server2.microsoft.com is not). The follow by a dot. Then the COM portion can be ONLY letters (no numeric or other characters) and it can only be 2 to 3 letters.

                  eg. The following input won't be accepted.
                  thisthatthisthat@hotmail (no .?? component)
                  t@hotmail.com (only 1 letter before@)
                  this@hotmail.comm (4 letters at the end, max can be only 3)
                  this@hotmail.c (1 letter at the end, min is 1)
                  this.that@hotmail.com (the first part cannot have dot)
                  this.that@ser.server1.hotmail.com (too complex at the end)
                  thisthat (no @)



                  All langugages have regular expression and you should use this to validate inputs.

                  In javascript:
                  var temp = trim(tt.email.value)
                  var pattern = /\w{2,}@(\w|\-|\_){3,}\.((\w|\-|\_){2,}\.){0,2}[a-z]{2,3}$/i
                  if (pattern.exec(temp) == null) {
                  alert("You have to enter a valid email address")
                  tt.email.focus();
                  return false;
                  }更多精彩文章及讨论,请光临枫下论坛 rolia.net
                  • learned a lot. thank u very much.
    • use regular expression as follows:
      Dim myinput As String
      Dim myregex As Regex = New Regex("(^\d{3}$);

      If not mylregex.IsMatch(myinput ) Then
      Alert("not valid")
      End If

      here is one link to start:

      http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=/quickstart/howto/doc/regexmatch.aspx
      • 正点.但我真的很烦regular expression 呐,很烦很烦
        • Once you know a bit more you will certainly enjoy it. BTW you need to import the name space like: Imports System.Text.RegularExpressions in vb.net in order to use it.