Skip to content

Commit

Permalink
Email and Password validation class added
Browse files Browse the repository at this point in the history
  • Loading branch information
Harounnn committed Apr 26, 2024
1 parent ea3da77 commit ddf29e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/com/example/readitai/SignUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@

import androidx.appcompat.app.AppCompatActivity;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class SignUp extends AppCompatActivity {

FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);

EditText username = (EditText) findViewById(R.id.usernamesu);
String usernameText = String.valueOf(username.getText());

mAuth = FirebaseAuth.getInstance();

EditText email = (EditText) findViewById(R.id.usernamesu);
String usernameText = String.valueOf(email.getText());

EditText password = (EditText) findViewById(R.id.passwordsu);
String passwordText = String.valueOf(password.getText());

EditText passwordAgain = (EditText) findViewById(R.id.passwordAgain);
String passwordAgainText = String.valueOf(passwordAgain.getText());
}

}
26 changes: 26 additions & 0 deletions app/src/main/java/com/example/readitai/Validator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.readitai;


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

public class Validator {

// Regular expression patterns for email and password validation
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
private static final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]).{7,}$";

private static final Pattern emailPattern = Pattern.compile(EMAIL_PATTERN);
private static final Pattern passwordPattern = Pattern.compile(PASSWORD_PATTERN);

public static boolean isValidEmail(String email) {
Matcher matcher = emailPattern.matcher(email);
return matcher.matches();
}

public static boolean isValidPassword(String password) {
Matcher matcher = passwordPattern.matcher(password);
return matcher.matches();
}
}

0 comments on commit ddf29e4

Please sign in to comment.