Java 解释什么&;amp表示验证电子邮件地址的代码
我正在尝试编写验证电子邮件地址的代码,我遇到了以下允许正确验证电子邮件地址的源代码,但是当我尝试在android studio上实现该代码时,它没有识别以下代码项&、>和!m_matcher 源代码:Java 解释什么&;amp表示验证电子邮件地址的代码,java,android,Java,Android,我正在尝试编写验证电子邮件地址的代码,我遇到了以下允许正确验证电子邮件地址的源代码,但是当我尝试在android studio上实现该代码时,它没有识别以下代码项&、>和!m_matcher 源代码: /** * Method to validate the EditText for valid email address * @param p_editText The EditText which is to be checked for valid email * @par
/**
* Method to validate the EditText for valid email address
* @param p_editText The EditText which is to be checked for valid email
* @param p_nullMsg The message that is to be displayed to the user if the text in the EditText is null
* @param p_invalidMsg The message that is to be displayed to the user if the entered email is invalid
* @return true if the entered email is valid, false otherwise
*/
private boolean validateEmail(EditText p_editText, String p_nullMsg, String p_invalidMsg)
{
boolean m_isValid = false;
try
{
if (p_editText != null)
{
if(validateForNull(p_editText,p_nullMsg))
{
Pattern m_pattern = Pattern.compile("([\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Za-z]{2,4})");
Matcher m_matcher = m_pattern.matcher(p_editText.getText().toString().trim());
if (!m_matcher.matches() && p_editText.getText().toString().trim().length() > 0)
{
m_isValid = false;
p_editText.setError(p_invalidMsg);
}
else
{
m_isValid = true;
}
}
else
{
m_isValid = false;
}
}
else
{
m_isValid = false;
}
}
catch(Throwable p_e)
{
p_e.printStackTrace(); // Error handling if application crashes
}
return m_isValid;
}
第2部分:
/**
* Method to check if some text is written in the Edittext or not
* @param p_editText The EditText which is to be checked for null string
* @param p_nullMsg The message that is to be displayed to the user if the text in the EditText is null
* @return true if the text in the EditText is not null, false otherwise
*/
private boolean validateForNull(EditText p_editText, String p_nullMsg)
{
boolean m_isValid = false;
try
{
if (p_editText != null && p_nullMsg != null)
{
if (TextUtils.isEmpty(p_editText.getText().toString().trim()))
{
p_editText.setError(p_nullMsg);
m_isValid = false;
}
else
{
m_isValid = true;
}
}
}
catch(Throwable p_e)
{
p_e.printStackTrace(); // Error handling if application crashes
}
return m_isValid;
}
请有人向我解释什么是&和>,以及为什么android studio不识别这些项目。最后,为什么这行代码中的感叹号用红色下划线****m_matcher
为这篇冗长的帖子道歉,并提前表示感谢 对于
&;您需要使用&
&
和
而不是
——看起来您是从一个网页复制的,该网页使用HTML编码了代码
将此行更改为:
if (!m_matcher.matches() && p_editText.getText().toString().trim().length() > 0)
致:
对于
&;您需要使用&
&
和
而不是
——看起来您是从一个网页复制的,该网页使用HTML编码了代码
将此行更改为:
if (!m_matcher.matches() && p_editText.getText().toString().trim().length() > 0)
致:
你从哪里复制的代码?@cricket_007从这里得到的:它部分工作。如果输入电子邮件地址的字段为空,则会设置错误,但不会检查格式。这是一个相当棘手的问题。这个stackoverflow问题对于电子邮件验证有一些很好的答案:你从哪里复制了这段代码?@cricket_007从这里得到了它:它部分起作用。如果输入电子邮件地址的字段为空,则会设置错误,但不会检查格式。这是一个相当复杂的问题。对于电子邮件验证,这个stackoverflow问题有一些很好的答案: