Checks if a string contains a valid SMS number using regex. - Android java.util.regex

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

Description

Checks if a string contains a valid SMS number using regex.

Demo Code


//package com.java2s;

public class Main {
    /**/*from w  w w  .j  a v a2 s. com*/
     * Checks if a string contains a valid SMS number.
     *
     * @param number String to validate
     * @return <code>true</code> if valid, otherwise <code>false</code>.
     */
    public static boolean isValidSMSnumber(String number) {
        return number.matches("\\d{7,10}");
    }
}

Related Tutorials