【正则】验证邮箱正则表达式

前端之家收集整理的这篇文章主要介绍了【正则】验证邮箱正则表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public static boolean isEmail(String strEmail) {
    String strPattern = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(strEmail);
    return m.matches();
}



检查EditText中输入的是否符合规则

import Android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class Main extends Activity {
    private EditText editText;
    private Button button;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editText = (EditText) findViewById(R.id.textId);
        editText.setText("EditText element");
        button = (Button) findViewById(R.id.btnId);
        button.setText("Check");
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkString(editText.getText().toString())) {
                    editText.setText("Corect");
                }
            }
        });
    }
 
    private boolean checkString(String s) {
        return s.matches("\\w*[.](Java|cpp|class)");
    }
}
原文链接:https://www.f2er.com/regex/362802.html

猜你在找的正则表达式相关文章