Created
June 12, 2017 20:46
-
-
Save bmsterling/2606fada9eb98dd46daf5d142f702cb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regexEmail = /^(([^<>()\[\]\\.,;:\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,}))$/; | |
export const validateEmail = (email) => { | |
let error = ''; | |
if (!email) { | |
error = 'Required'; | |
} else if (!regexEmail.test(email)) { | |
error = 'Invalid email address'; | |
} | |
return error; | |
}; | |
const regexName = /^([ \u00c0-\u01ffa-zA-Z'-])+$/; | |
export const validateName = (name, checkIfEmpty) => { | |
const nameString = String(name || ''); | |
let error = ''; | |
if (checkIfEmpty && nameString.length <= 0) { | |
error = 'Required'; | |
} else if (!regexName.exec(nameString)) { | |
error = 'Only letters, -, and \' are acceptible'; | |
} | |
return error; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment