All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vfdtech.implementations.PhoneNumberUtils Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project. This is designed for Java 1.8

There is a newer version: 1.0.0
Show newest version
package org.vfdtech.implementations;

import org.apache.commons.lang3.StringUtils;
import org.vfdtech.enums.CountryEnum;
import org.vfdtech.interfaces.IPhoneNumberUtils;

import java.util.regex.Pattern;

import static java.util.regex.Pattern.compile;

public class PhoneNumberUtils implements IPhoneNumberUtils {
    static Pattern startsWith0pattern = compile("0\\d{10}");
    static Pattern startsWith234pattern = compile("234\\d{10}|\\+234\\d{10}");

    @Override
    public boolean isValid(String phoneNumber, CountryEnum... country) {
        return country.length == 0 && isNgValid(phoneNumber);
    }

    @Override
    public String networkProvider(String phoneNumber, CountryEnum... country) {
        return "";
    }

    private boolean isNgValid(final String phoneNumber) {
        //Validate 11 numbers or at most 13
        //No Special Chars
        return
                StringUtils.isNotBlank(phoneNumber)
                        &&
                        (startsWith234(phoneNumber) || startsWith0(phoneNumber));
    }

    private boolean startsWith234(final String value) {
        return startsWith234pattern.matcher(value).matches();
    }

    private boolean startsWith0(final String value) {
        return startsWith0pattern.matcher(value).matches();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy