validation - What is the minimum length of a valid international phone number? -
i need validate user input of international phone number. according e.164, maximum length 15 digits, unable find info minimum. consider digits only, no plus sign or separators.
as per different sources, think minimum length in e-164 format depends on country country. eg:
for israel: minimum phone number length (excluding country code) 8 digits. - official source (country code 972)for sweden : minimum number length (excluding country code) 7 digits. - official source (country code 46)
for solomon islands 5 fixed line phones. - source (country code 677)
... , on. including country code, minimum length 9 digits sweden , 11 state of israel , 8 solomon islands.
edit (clean solution): actually, instead of validating international phone number having different checks length etc, can utilize google's libphonenumber library. can validate phone number in e164 format directly. take business relationship , don't need give country if number in valid e164 format. pretty good! taking example:
string phonenumbere164format = "+14167129018" phonenumberutil phoneutil = phonenumberutil.getinstance(); seek { phonenumber phonenumberproto = phoneutil.parse(phonenumbere164format, null); boolean isvalid = phoneutil.isvalidnumber(phonenumberproto); // returns true if valid if (isvalid) { // actions perform if number valid } else { // necessary actions if not valid } } grab (numberparseexception e) { system.err.println("numberparseexception thrown: " + e.tostring()); }
if know country validating numbers, don;t need e164 format , can specify country in .parse
function instead of passing null
.
validation
No comments:
Post a Comment