Skip to content

Instantly share code, notes, and snippets.

@bmsterling
Created June 12, 2017 20:46
Show Gist options
  • Save bmsterling/2606fada9eb98dd46daf5d142f702cb6 to your computer and use it in GitHub Desktop.
Save bmsterling/2606fada9eb98dd46daf5d142f702cb6 to your computer and use it in GitHub Desktop.
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