Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.widget.EditText;

public class Main {
    public static boolean EmailPassNickCheck(EditText email, EditText password, EditText nick) {
        if (nick != null) {
            if (nick.getText().toString().trim().equals("")) {
                nick.setError("Empty name please revise!");
                return false;
            }
        } else if (email.getText().toString().trim().equals("")) {
            email.setError("Empty email please revise!");
            return false;
        } else if (password.getText().toString().trim().equals("")) {
            password.setError("Empty password please revise!");
            return false;
        } else if (!EmailValidation(email)) {
            email.setError("Incorrect Email please revise!");
            return false;
        }
        return true;
    }

    public static boolean EmailValidation(EditText email) {
        String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher;
        matcher = pattern.matcher(email.getText().toString());

        return matcher.matches();
    }
}