The decision string in Android must contain letters or numbers _android

Source: Internet
Author: User
Tags wrapper

The public static Boolean isletterdigit (String str) {
  Boolean isdigit = false;//defines a Boolean value that is used to indicate whether a numeric Boolean is included
     Isletter = false;//defines a Boolean value that indicates whether to include the letter for
     (int i=0; I
       if (Character.isdigit (Str.charat (i))) {   // Judge each character
         IsDigit = True
       using the method of judging numbers in the Char wrapper class if (Character.isletter (Str.charat (i))) {  //judge each character Isletter = True using the method of judging letters in the Char wrapper class
         ;
     String regex = "^[a-za-z0-9]+$";
    Boolean isright = IsDigit && isletter&&str.matches (regex);
 return isright;
 
 }

Android determines whether edittext input numbers, Chinese, or alphabetic methods

String txt = edinput.gettext (). toString ();

  Pattern p = pattern.compile ("[0-9]*"); 
   Matcher m = p.matcher (TXT); 
   if (M.matches ()) {
   Toast.maketext (main.this, "Enter a number", Toast.length_short). Show (); 
   P=pattern.compile ("[a-za-z]");
   M=p.matcher (TXT);
   if (M.matches ()) {
   Toast.maketext (main.this, "input is a letter", Toast.length_short). Show ();
   P=pattern.compile ("[\u4e00-\u9fa5]");
   M=p.matcher (TXT);
   if (M.matches ()) {
   Toast.maketext (main.this, "input is Kanji", toast.length_short). Show ();
   

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.