Email and phone Number Validation in android

后端 未结 12 1253
青春惊慌失措
青春惊慌失措 2020-12-02 11:03

I have a registration form in my application which I am trying to validate. I\'m facing some problems with my validation while validating the phone number and email fields.<

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 11:40

    Try this

    public class Validation {
    
        public final static boolean isValidEmail(CharSequence target) {
            if (target == null) {
            return false;
            } else {
            return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
            }
        } 
    
        public static final boolean isValidPhoneNumber(CharSequence target) {
            if (target.length()!=10) {
                return false;
            } else {
                return android.util.Patterns.PHONE.matcher(target).matches();
            }
        }
    
    }
    

提交回复
热议问题