Skip to content

Commit

Permalink
regexr parts
Browse files Browse the repository at this point in the history
  • Loading branch information
akashTharuka committed Mar 20, 2021
1 parent ac8dc26 commit c3b2173
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions public/SignUp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<small>Error message</small>
</div>

<small class="pswHint">Minimum eight characters, at least one letter and one number</small>

<div class="form-control">
<input type="password" name="confirmPsw" class="newPsw signUp confirm" id="c_psw" placeholder="Confirm your password">
<label class="form-label" for="c_psw">Confirm Password : </label>
Expand Down
5 changes: 4 additions & 1 deletion public/assets/css/styles_signup.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ body{
visibility: visible;
}


.pswHint{
position: relative;
left: 15px;
}

.button.signUp{
border: none;
Expand Down
44 changes: 40 additions & 4 deletions public/assets/javascript/formController.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ async function isEmail(email){
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email);
}

async function isPhoneNumber(phone){
//RegExr phone number validation
let phoneno = /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/;
if(phone.value.match(phoneno)) {
return true;
}
else {
return false;
}
}

async function isPassword(password){
// RegExr password validation
let psw = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
if (password.value.match(psw)){
return true;
}
else{
return false;
}
}

//login validation front and back
let validateExistingEmailAndPassword = async (emailInput, pswInput) => {

Expand Down Expand Up @@ -325,13 +347,23 @@ let validateNonEmpty = async (nonEmpty) => {
let name = fieldName.charAt(0).toUpperCase() + fieldName.slice(1);
let errMsg = name + " cannot be blank";

if (input.value !== ''){
setSuccess(input);
}
else{
if (input.value == ''){
setError(input, errMsg);
correct = false;
}
else if (input.name == 'phone'){
if (await isPhoneNumber(input)){
console.log("here");
setSuccess(input);
}
else{
setError(input, 'invalid format');
correct = false;
}
}
else{
setSuccess(input);
}
}
};

Expand All @@ -345,6 +377,10 @@ let validateNewPassword = async (oldPsw, psw) => {
setError(newPswField, 'Password cannot be blank');
correct = false;
}
else if (! await isPassword(newPswField)){
setError(newPswField, 'Invalid password format');
correct = false;
}
//check if there is an old password field
//and if the old password is equal to the new password
else if ((oldPsw.length > 0) && (oldPsw[0].value === newPswField.value)){
Expand Down

0 comments on commit c3b2173

Please sign in to comment.