如何将验证在android手机号码,与QUOT;始于+ QUOT;? [英] how to place validation for phone number in android,"starts with +"?
本文介绍了如何将验证在android手机号码,与QUOT;始于+ QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
模式P = Pattern.compile(^ \\ +(?:?[0-9]){6,14} [0-9] $);
//匹配给定的字符串与模式
匹配M = p.matcher(numberstr);
//检查是否发现匹配
布尔numberFound = m.matches();
解决方案
1)如果您想验证文本字段,这样他们就可以,你需要把XML只输入电话号码
安卓phoneNumber的=真
2),或者,如果你想验证一个电话号码,利用 Linkify 类,你可以使用的<一个href="http://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html">MatchFilter接口提供得到公认的电话号码储存在CharSequence的。
Pattern p = Pattern.compile("^\\+(?:[0-9] ?){6,14}[0-9]$");
//Match the given string with the pattern
Matcher m = p.matcher(numberstr);
//check whether match is found
boolean numberFound = m.matches();
解决方案
1) If you want to validate a text field, so they can enter only phone numbers you need to put in XML
android:phoneNumber="true"
2) Or if you want to validate a phone number make use of the Linkify class, and you can make use of the MatchFilter interface it provides to get the recognized phone numbers in the charsequence.
这篇关于如何将验证在android手机号码,与QUOT;始于+ QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文