string - Validation for a cell number in Android -


i have ui user enters cell number , number stored in string variable , stored database.

i want validate string check whether string not contain characters.

how do that?

below string code.

edittext edittext3 = (edittext) this.findviewbyid(r.id.edittext2); setnum = edittext3.gettext().tostring(); //setnum contain link 8081124589 

to validate string, use

if (setnum.matches(regexstr)) 

where regexstr can be:

//matches numbers string regexstr = "^[0-9]*$"  //matches 10-digit numbers string regexstr = "^[0-9]{10}$"  //matches numbers , dashes, order really. string regexstr = "^[0-9\\-]*$"  //matches 9999999999, 1-999-999-9999 , 999-999-9999 string regexstr = "^(1\\-)?[0-9]{3}\\-?[0-9]{3}\\-?[0-9]{4}$" 

there's long regex validate phones in (7 10 digits, extensions allowed, etc.). source answer: a comprehensive regex phone number validation

string regexstr = "^(?:(?:\\+?1\\s*(?:[.-]\\s*)?)?(?:\\(\\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\\s*\\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\\s*(?:[.-]\\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\\s*(?:[.-]\\s*)?([0-9]{4})(?:\\s*(?:#|x\\.?|ext\\.?|extension)\\s*(\\d+))?$" 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -