The below code is for a student registration application. For some reason the two validations shown first from the below code are not allowing the data to input into the database and then be fetched when logging in from the Main Activity Page.
Without these two lines the application works perfectly. Can someone tell me the issue?
Issues
//issue
if (!uname.getText().toString().matches("[c|C][0-9]{7}"))
{uname.setError("Incorrect ID Format");}
//issue
if (!pass1.getText().toString().matches("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"))
{pass1.setError("Incorrect Password Format");}
SignUp.Java
package com.example.oliver.beckettreg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widet.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SignUp extends Activity {
DatabaseHelper helper = new DatabaseHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
}
public void onSignUpClick(View v)
{
if(v.getId()== R.id.Bsignupbutton)
{
EditText name = (EditText)findViewById(R.id.TFname);
EditText email = (EditText)findViewById(R.id.TFemail);
EditText uname = (EditText)findViewById(R.id.TFuname);
EditText pass1 = (EditText)findViewById(R.id.TFpass1);
EditText pass2 = (EditText)findViewById(R.id.TFpass2);
String namestr = name.getText().toString();
String emailstr = email.getText().toString();
String unamestr = uname.getText().toString();
String pass1str = pass1.getText().toString();
String pass2str = pass2.getText().toString();
if(!pass1str.equals(pass2str))
{
//popup msg
Toast pass = Toast.makeText(SignUp.this , "Passwords don't match!" , Toast.LENGTH_SHORT);
pass.show();
}
else
{
if (name.getText().toString().length() == 0)
{name.setError("Name Required");}
if (!email.getText().toString().matches("[a-z]\\.[a-z]*[0-9]*@student\\.leedsbeckett\\.ac\\.uk"))
{email.setError("Incorrect Email Format");}
//issue
if (!uname.getText().toString().matches("[c|C][0-9]{7}"))
{uname.setError("Incorrect ID Format");}
//issue
if (!pass1.getText().toString().matches("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"))
{pass1.setError("Incorrect Password Format");}
else{
//insert the details in database
Contact c = new Contact();
c.setName(namestr);
c.setEmail(emailstr);
c.setUname(unamestr);
c.setPass(pass1str);
helper.insertContact(c);
Toast pass = Toast.makeText(SignUp.this , "User Registered" , Toast.LENGTH_SHORT);
pass.show();
}
}
}
}
public void onButtonClick(View v) {
if (v.getId() == R.id.Blogin2) {
Intent i = new Intent(SignUp.this, com.example.oliver.beckettreg.MainActivity.class);
startActivity(i);
}
}
}
Correct format for email would be a.aaaaaa8234@leedsbeckett.ac.uk
Correct format for uname would be c3400554
Correct format for password would be:
- a digit must occur at least once
- a lower case letter must occur at least once
- an upper case letter must occur at least once
- a special character must occur at least once
- no whitespace allowed in the entire string
- anything, at least eight places