我有一份登记表,在提交前需要确认。表单包含以下字段:姓名、电子邮件、联系人号码和密码。我需要的名字有一个值,电子邮件有正确的格式,联系号码应该是数字至少10个号码和密码至少6个字符。

最佳答案

试试这个

vUsername = etUsername.getText().toString();
vFirstname = etFirstname.getText().toString();
vEmail = etEmail.getText().toString();
vPwd = etPwd.getText().toString();
vCpwd = etCpwd.getText().toString();

if("".equalsIgnoreCase(vUsername) //vUsername.equalsIgnoreCase("") could lead to NPE
   || "".equalsIgnoreCase(vFirstname)
   || "".equalsIgnoreCase(vEmail)
   || "".equalsIgnoreCase(vPwd)
   || "".equalsIgnoreCase(vCpwd) )
{
    Toast.makeText(userRegistration.this, "All Fields Required.",
         Toast.LENGTH_SHORT).show();
}
checkemail(vEmail);
if(emailcheck==true)
{
    // your code here
}

public void checkemail(String email)
{
    Pattern pattern = Pattern.compile(".+@.+\\.[a-z]+");
    Matcher matcher = pattern.matcher(email);
    emailcheck = matcher.matches();
}

07-24 09:55