Last active
December 27, 2018 22:16
-
-
Save wtho/d5f3cfd6bc4c61b14d24d7aae5bde4ef to your computer and use it in GitHub Desktop.
Email-Validator that requires SLD for vue-form
This file contains hidden or 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 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 | |
| }; |
This file contains hidden or 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
| <validate> | |
| <input v-model="something" name="something" email-sld /> | |
| <!-- | |
| slot name inside field-messages would be: <div slot="email-sld">...</div> | |
| --> | |
| </validate> |
This file contains hidden or 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
| import { customValidators } from './path/to/email-sld-regex' | |
| const options = { | |
| validators: { | |
| 'email-sld': customValidators.emailWithSld | |
| } | |
| } | |
| Vue.use(VueForm, options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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