Verify that the input in Android is Chinese characters and phone number, email authentication, IP address can be verified by port number

Source: Internet
Author: User

1, verify whether it is a Chinese character

Verify that the nickname private Boolean verifynickname () {String nickname = Edt_username.gettext (). toString ();            if (nickname = = NULL | | nickname.length () = = 0) {Edt_username.seterror ("cannot be empty");        return false;        } int len = 0;        char[] Nickchar = Nickname.tochararray ();            for (int i = 0; i < nickchar.length; i++) {if (Ischinese (Nickchar[i])) {len + 2;            } else {len + 1; }} if (Len < 4 | | len >) {edt_username.seterror ("the correct nickname should be \n1, 4-15 characters \n2, 2-7 kanji \n3, not mail            box and mobile phone number ");        return false;    } return true;        Private Boolean Ischinese (char c) {Character.unicodeblock UB = Character.UnicodeBlock.of (c); if (UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS | | ub = = Character.UnicodeBlock.CJK_COMPATIBILITY_I deographs | |  UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A              || UB = = Character.UnicodeBlock.GENERAL_PUNCTUATION | | UB = = Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION | |        UB = = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {return true;    } return false; }

2. Verify the phone number. Mailbox

Infer whether the phone number is    private Boolean isphone (String inputtext) {        pattern P = pattern                . Compile ("^ (13[0-9]) | ( 15[^4,\\D]) | (18[0,0-9])) \\d{8}$ ");        Matcher m = P.matcher (inputtext);        return m.matches ();    }    Infer whether the format is e-mail public    boolean isemail (string email) {        string str = "^ ([a-za-z0-9_\\-\\.] +) @ ((\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | ([a-za-z0-9\\-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?) $";        Pattern p = pattern.compile (str);        Matcher m = p.matcher (email);        return m.matches ();    }

3,IP address can be verified with port number, available with port number (1024-65536)

Private Boolean Matcherip (String IP) {        pattern pattern = pattern.compile ("^ (?! \\d\\d\\d) (\\d+|1\\d\\d|2[0-4]\\d|25[0-5]) "                +" \ \. ( (?

!\\d\\d\\d) (\\d+|1\\d\\d|2[0-4]\\d|25[0-5]) " +" \ \. ( (?! \\d\\d\\d) (\\d+|1\\d\\d|2[0-4]\\d|25[0-5]) " +" \ \. ( (?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5] " +":((102[4-9]) | ( 10[3-9]\\d) | ([1-5]\\d{3,4}) | (6[0-4]\\d{3}) | (65[0-4]\\d{2}) | (655[0-2]\\d) | (6553[0-5])) $"); Matcher Matcher = Pattern.matcher (IP); return matcher.matches (); }



4, Match/* 1234567890 * * ("/*" starts with a numeric space in the middle, ending with "*/")

Pattern pattern = pattern.compile ("/*\\/*\\s*\\d*\\s*\\*/*"); Matcher Matcher = Pattern.matcher ("regular"/*  123   */Hello World, just the form Hello World "); Replace the first regular data System.out.println (Matcher.replaceall (""));


5, regular form of eclipse search often used
1,eclipse Ctrl+f Open the Find box 2. Check Regular expressions (normal form) to remove the/* */(Eclipse)        /\* (. | [\ r \ n]) *?\*/Remove//(Eclipse)             //.*$ Remove import (Eclipse)     import.*$ remove blank line (Eclipse)         ^\s*\n remove empty line (UE)               %[^t]++^p

6, the time display in the video playback progress bar
Minutes
String am = String.Format ("%02d", TTOTAL/60);
Seconds
String as = String.Format ("%02d", ttotal% 60);
Tiempototal.settext (AM + ":" + As);







Verify that the input in Android is Chinese characters and phone number, email authentication, IP address can be verified by port number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.