Validates given phone Number string using android.util.Patterns#PHONE pattern - Android java.util.regex

Android examples for java.util.regex:Phone Number Pattern

Description

Validates given phone Number string using android.util.Patterns#PHONE pattern

Demo Code


//package com.java2s;
import android.text.TextUtils;
import android.util.Patterns;

public class Main {
    /**// w ww. j  a  v  a 2  s  .  c  o  m
     * Validates given phoneNumber string using {@link android.util.Patterns#PHONE} pattern
     *
     * @param phoneNumber to validate
     * @return true if phoneNumber is valid, otherwise false
     */
    public static boolean isValidPhone(final String phoneNumber) {
        if (TextUtils.isEmpty(phoneNumber)) {
            return false;
        }

        return Patterns.PHONE.matcher(phoneNumber).matches();
    }
}

Related Tutorials