Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Created March 19, 2017 21:27
Show Gist options
  • Save helloncanella/466d8d961ccd247d76c2fe773cae6b6c to your computer and use it in GitHub Desktop.
Save helloncanella/466d8d961ccd247d76c2fe773cae6b6c to your computer and use it in GitHub Desktop.
Instructions to render a group of fieldsets
const validateEmail = ({ email }) => {
const regex = /^(([^<>()\[\]\\.,;:\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,}))$/;
if (!regex.test(email)) throw 'email format is not correct!'
}
const validatePasswords = ({ password, confirmation }) => {
if (password !== confirmation) throw 'passwords do not match!'
}
const validateUsername = ({ username }) => {
if (!isNaN(username)) { throw 'username cannot be a number' }
}
const fieldsets = [
{
name: "username",
inputs: [{ name: 'username', type: 'text', placeholder: "username" }],
validator: validateUsername
},
{
name: "email",
inputs: [{ name: 'email', type: 'text', placeholder: "email" }],
validator: validateEmail
},
{
name: "passwords",
validator: validatePasswords,
inputs: [
{ name: 'password', type: 'password', placeholder: "password" },
{ name: 'confirmation', type: 'password', placeholder: "password confirmation" }
],
},
]
export default fieldsets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment