Skip to content

Instantly share code, notes, and snippets.

@wtho
Last active December 27, 2018 22:16
Show Gist options
  • Select an option

  • Save wtho/d5f3cfd6bc4c61b14d24d7aae5bde4ef to your computer and use it in GitHub Desktop.

Select an option

Save wtho/d5f3cfd6bc4c61b14d24d7aae5bde4ef to your computer and use it in GitHub Desktop.
Email-Validator that requires SLD for vue-form
const emailRegex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@([a-z0-9][a-z0-9-]*)*[a-z0-9]\.[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
// SLD = second layer domain
const emailWithSld = function (value, attrValue, vnode) {
return emailRegex.test(value);
};
export const customValidators = {
emailWithSld
};
<validate>
<input v-model="something" name="something" email-sld />
<!--
slot name inside field-messages would be: <div slot="email-sld">...</div>
-->
</validate>
import { customValidators } from './path/to/email-sld-regex'
const options = {
validators: {
'email-sld': customValidators.emailWithSld
}
}
Vue.use(VueForm, options);
@expomas

expomas commented Sep 16, 2018

Copy link
Copy Markdown

Thanks for the extra explanation. I believe there's a typo in the email-sld-regex.js chunk: it should be

return emailRegex.test(value)

otherwise works great, thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment