A check e-mail address is the effectiveness of the procedures for regular expression

  Abstract: A check e-mail address the effectiveness of the procedures for the regular expression 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> 

  This article is reproduced multiple Internet, such as China's software: http://dev.csdn.net/article/27/27762.shtm, but the text of a regular expression "\ \ w + @ (\ \ w +.) + [az] (2,3) "I think it should be changed to:" \ \ w + @ (\ \ w + \ \.) + [az] (2,3), "because". "can represent any character, is the yuan characters need to escape.    Otherwise, like the following e-mail addresses so that the address is valid. 
  C: \ java> java Test zz3zcwb@sina.com.cn.net34523542ffrdasfafasfsaf 
  Valid e-mail addresses 

  Below is the text: 

  Import java.util.regex.Pattern; 
  Import java.util.regex.Matcher; 

  Public class Test ( 
  Public static void main (String [] args) ( 

  If (args.length! = 1) ( 
  System.out.println ( "Please enter a parameter!"); 
  System.exit (0); 
  ) 
  / / Here and I have to back up, which read: Pattern p = Pattern.compile ( "\ \ w + @ (\ \ w +.)+[ az] (2,3)"); 
  Pattern p = Pattern.compile ( "\ \ w + @ (\ \ w + \ \.) + [Az] (2,3)"); 
  Matcher m = p.matcher (args [0]); 
  Boolean b = m.matches (); 
  If (b) ( 
  System.out.println ( "valid e-mail addresses"); 
  Else () 
  System.out.println ( "invalid email address"); 
  ) 
  ) 
  ) 

  <table Width="661" border="0"> <tr> <td width="330"> 
  Implementation: 
  C: \ java> java Test abc@def.nujpt.edu.cn 
  Valid e-mail addresses 

  C: \ java> java Test abc @ def 
  Invalid e-mail address 

  C: \ java> java Test abc@de_f.com.cn 
  Valid e-mail addresses 

  C: \ java> java Test abc@de_f.com.cn 
  Valid e-mail addresses 

  C: \ java> java Test abc@de_f.com.cn3 
  Invalid e-mail address 

  C: \ java> java Test abc@de_f.com.cncom 
  Invalid e-mail address 

  </ Td> <td width="321"> </ td> </ tr> </ table> 

  C: \ java> java Test ab_c@de_f.com.cncom 
  Invalid e-mail address 

  C: \ java> java Test ab_c@de_f.com.cn 
  Valid e-mail addresses 

  C: \ java> 
  Notes: 
  "\ \ W + @ (\ \ w + \ \.) + [Az] (2,3)" 

  In the regular expression in the \ w characters that arbitrary words, the scope of az, AZ, 0-10-9 _ because of java \ is originally escaped symbols, if only for the write \ w Ambiguity may occur, or even wrong, So write to: \ \ w 

  + Means that more than once, so \ \ w + on behalf of arbitrary length of the string, but does not include other special characters, such as _,-,$,&,*, huh, if the e-mail really wants to completely effective check it on a regular expression is not so long, huh, interested can read their own Write. 

  I would like to comment on the back of simple, @ must appear, but only once, @ written directly on the line. 

  \ \ W + \ \. Arbitrary strings behind the DOT, we all know that this is the characteristics of domain names, and I wrote (\ \ w + \ \.) + Why is it, because the mail server may be two domain names, three domain names, or if we do not bring…… () +, abc@sina.com effective, and abc@mail.sina.com is invalid, so this is necessary. 

  Finally, [az] (2,3), taking into account the general domain no final figures capital rarely see (I think generally the case should be ignored), and a minimum of not less than 2, such as cn, us, etc. up to more than three, such as com, org, etc., and so they wrote the above forms. 


  Just started learning the regular expression, Oh, a lot of ideas also quite naive, a little bit more complex on the hinder, and cattle were also looking to the guidance of a lot :-) 



  Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply