Android Regular expression Verification phone number, name (including minority), Social Security number

Source: Internet
Author: User

Recent project new features, need to mobile phone number, name, ID card number and other information to verify, the best way is through regular expression to verify, on-line check some information, wrote these tools methods.

1. Verify the phone number

Rule: The first digit can only be 1, the second digit is 3-8, 3-11 bits is any number

    /** Mobile phone number field check, 1th digit: 1; 2nd bit: {3, 4, 5, 6, 7, 8} any number; 第3-11位: 0-9 any number * @param value * @return*/     Public Staticboolean istelphonenumber (String value) {if(Value! =NULL&& value.length () = = One) {pattern pattern= Pattern.compile ("^1[3|4|5|6|7|8][0-9]\\d{8}$"); Matcher Matcher=Pattern.matcher (value); returnmatcher.matches (); }        return false; }

2. Name Verification The name is verified here, and the user can enter anything in the input box, but this method is adjusted when clicking on the verification button.

The validation rules are: Names are added by Chinese or Chinese characters "?","· "The composition, and," point "can only have one," point "position can not be in the first and not at the end, only between the characters will be verified through.

    /** * Verify that the name entered is "Chinese" or whether it contains "•"*/     Public Staticboolean islegalname (String name) {if(Name.contains ("·") || Name.contains ("?")){            if(Name.matches ("^[\\u4e00-\\u9fa5]+[?] [\\u4e00-\\u9fa5]+$")){                return true; }Else {                return false; }        }Else {            if(Name.matches ("^[\\u4e00-\\u9fa5]+$")){                return true; }Else {                return false; }        }    }

3. Verify the ID number

Verify the ID number

The rule is: consists of 15 digits or 18 digits (17 digits Plus "x"), 15-bit pure numbers nothing to say, 18-bit words, can be 18-bit pure numbers, or 17 digits plus "x"

    /* *     * Verify that the entered ID number is     valid */public     static  boolean islegalid (String ID) {        if (Id.touppercase (). Matches ("(^\\d{15}$) | ( ^\\D{17} ([0-9]| X) ($)){            returntrue;        } Else {            returnfalse;        }    }

The above regular expression validates the result, with true and false returns

Android Regular expression verifies phone number, name (including minority), Social Security 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.