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 isValidEmail = ( email ) => regexEmail . test ( email ) ; export const getFieldName = ( uid ) => `input-${ uid }` ; export const validate = ( fieldsWithValue , { t } ) => { const errors = fieldsWithValue . map ( ( field ) => { if ( field . required === 'true' && ! field . value ) { return t ( "Form Blank Validation" , { field : field . label } ) ; } else if ( field . value !== '' && field . kind === 'email' && ! isValidEmail ( field . value ) ) { return t ( "Form Email Validation" , { field : field . label } ) ; } return false ; } ) ; return errors . filter ( ( error ) => ! ! error ) ; } ; export const fields = ( settings ) => { const fields = settings && settings . fields ? settings . fields : [ ] ; return fields . filter ( ( f ) => f . kind !== 'greetings' ) ; } ; export const addValueToFields = ( fields , values ) => fields . map ( ( field ) => ( { ... field , value : values [ getFieldName ( field . uid ) ] , } ) ) ;