Android 校验email是否合法
这个其实跟JAVA中是一样的。例子:
String regEx =
"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
+"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
+"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+"([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";
public void btnValidateEmailAddress(View v)
{
strEmailAddress = editTextEmail.getText().toString().trim();
Matcher matcherObj = Pattern.compile(regEx).matcher(strEmailAddress);
if (matcherObj.matches())
{
Toast.makeText(v.getContext(), strEmailAddress+" is valid", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(v.getContext(), strEmailAddress+" is InValid", Toast.LENGTH_SHORT).show();
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!