久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      Android正則表達式

      要嚴格的驗證手機號碼,必須先要清楚現(xiàn)在已經(jīng)開放了哪些數(shù)字開頭的號碼段,目前國內(nèi)號碼段分配如下:

      移動:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

      聯(lián)通:130、131、132、152、155、156、185、186

      電信:133、153、180、189、(1349衛(wèi)通)

      驗證手機號:

        public class ClassPathResource {     public static boolean isMobileNO(String mobiles) {       Pattern p = Pattern           .compile("^(([-])|([^,//D])|([,-]))//d{}$");       Matcher m = p.matcher(mobiles);       System.out.println(m.matches() + "---");       return m.matches();     }     public static void main(String[] args) throws IOException {       System.out.println(ClassPathResource.isMobileNO(""));     }   }  public class ClassPathResource {      public static boolean isMobileNO(String mobiles) {        Pattern p = Pattern            .compile("^(([-])|([^,//D])|([,-]))//d{}$");        Matcher m = p.matcher(mobiles);        System.out.println(m.matches() + "---");        return m.matches();      }      public static void main(String[] args) throws IOException {        System.out.println(ClassPathResource.isMobileNO(""));      }    } 

      驗證郵箱:

        public static boolean isEmail(String strEmail) {      String strPattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";     Pattern p = Pattern.compile(strPattern);     Matcher m = p.matcher(strEmail);     return m.matches();   }   public static boolean isEmail(String strEmail) {      String strPattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";      Pattern p = Pattern.compile(strPattern);      Matcher m = p.matcher(strEmail);      return m.matches();    }    

      檢查EditText中輸入的是否符合規(guī)則:

        import Android.app.Activity;   import android.os.Bundle;   import android.view.View;   import android.widget.Button;  import android.widget.EditText;    public class Main extends Activity {     private EditText editText;     private Button button;         @Override     public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.main);       editText = (EditText) findViewById(R.id.textId);       editText.setText("EditText element");       button = (Button) findViewById(R.id.btnId);       button.setText("Check");       button.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View v) {           if (checkString(editText.getText().toString())) {             editText.setText("Corect");           }         }       });     }         private boolean checkString(String s) {       return s.matches("\w*[.](Java|cpp|class)");     }   }  import Android.app.Activity;    import android.os.Bundle;    import android.view.View;    import android.widget.Button;    import android.widget.EditText;    public class Main extends Activity {      private EditText editText;      private Button button;          @Override     public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        editText = (EditText) findViewById(R.id.textId);        editText.setText("EditText element");        button = (Button) findViewById(R.id.btnId);        button.setText("Check");        button.setOnClickListener(new View.OnClickListener() {          @Override         public void onClick(View v) {            if (checkString(editText.getText().toString())) {              editText.setText("Corect");            }          }        });      }          private boolean checkString(String s) {        return s.matches("\w*[.](Java|cpp|class)");      }    } 

      常用正則表達式收集

      正則表達式用于字符串處理、表單驗證等場合,實用高效。現(xiàn)將一些常用的表達式收集于此,以備不時之需。

      匹配中文字符的正則表達式: [u4e00-u9fa5]

      評注:匹配中文還真是個頭疼的事,有了這個表達式就好辦了

      匹配雙字節(jié)字符(包括漢字在內(nèi)):[^x00-xff]

      評注:可以用來計算字符串的長度(一個雙字節(jié)字符長度計2,ASCII字符計1)

      匹配空白行的正則表達式:ns*r

      評注:可以用來刪除空白行

      匹配HTML標記的正則表達式:<(S*?)[^>]*>.*?|<.*? />

      評注:網(wǎng)上流傳的版本太糟糕,上面這個也僅僅能匹配部分,對于復(fù)雜的嵌套標記依舊無能為力

      匹配首尾空白字符的正則表達式:^s*|s*

      評注:可以用來刪除行首行尾的空白字符(包括空格、制表符、換頁符等等),非常有用的表達式

      匹配Email地址的正則表達式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*

      評注:表單驗證時很實用

      匹配網(wǎng)址URL的正則表達式:[a-zA-z]+://[^s]*

      評注:網(wǎng)上流傳的版本功能很有限,上面這個基本可以滿足需求

      匹配帳號是否合法(字母開頭,允許5-16字節(jié),允許字母數(shù)字下劃線):^[a-zA-Z][a-zA-Z0-9_]{4,15}

      評注:表單驗證時很實用

      匹配國內(nèi)電話號碼:d{3}-d{8}|d{4}-d{7}

      評注:匹配形式如 0511-4405222 或 021-87888822

      匹配騰訊QQ號:[1-9][0-9]{4,}

      評注:騰訊QQ號從10000開始

      匹配中國郵政編碼:[1-9]d{5}(?!d)

      評注:中國郵政編碼為6位數(shù)字

      匹配身份證:d{15}|d{18}

      評注:中國的身份證為15位或18位

      匹配ip地址:d+.d+.d+.d+

      評注:提取ip地址時有用

      匹配特定數(shù)字:

      ^[1-9]d*    //匹配正整數(shù)
      ^-[1-9]d*   //匹配負整數(shù)
      ^-?[1-9]d*   //匹配整數(shù)
      ^[1-9]d*|0  //匹配非負整數(shù)(正整數(shù) + 0)
      ^-[1-9]d*|0   //匹配非正整數(shù)(負整數(shù) + 0)
      ^[1-9]d*.d*|0.d*[1-9]d*   //匹配正浮點數(shù)
      ^-([1-9]d*.d*|0.d*[1-9]d*)  //匹配負浮點數(shù)
      ^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)  //匹配浮點數(shù)
      ^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0   //匹配非負浮點數(shù)(正浮點數(shù) + 0)
      ^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0  //匹配非正浮點數(shù)(負浮點數(shù) + 0)

      評注:處理大量數(shù)據(jù)時有用,具體應(yīng)用時注意修正

      匹配特定字符串:

      ^[A-Za-z]+  //匹配由26個英文字母組成的字符串
      ^[A-Z]+  //匹配由26個英文字母的大寫組成的字符串
      ^[a-z]+  //匹配由26個英文字母的小寫組成的字符串
      ^[A-Za-z0-9]+  //匹配由數(shù)字和26個英文字母組成的字符串
      ^w+  //匹配由數(shù)字、26個英文字母或者下劃線組成的字符串

      評注:最基本也是最常用的一些表達式

      以上內(nèi)容就是小編跟大家分享的android正則表達式大全,希望對大家有用。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號