Last active
January 23, 2018 08:14
-
-
Save clonekim/4d7457ee8f9f5db0ca5ebd9f4da84140 to your computer and use it in GitHub Desktop.
This file contains 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
<form method="POST" @submit="validateBeforeSubmit"> | |
<span>Name</span> | |
<input type="text" class="formText" v-model.trim="user.username"> | |
<p class="bind-error" v-show="validation.hasError('user.username')">{{validation.firstError('user.nickname')}}</p> | |
</form> |
This file contains 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 Vue from 'vue' | |
import SimpleVueValidator from 'simple-vue-validator' | |
import * as CustomValidator from './validator' | |
Vue.use(SimpleVueValidator) | |
new Vue({ | |
el: '.container', | |
data() { | |
return { | |
user: { | |
username: '' | |
} | |
} | |
}, | |
validators: { | |
'user.nickname': CustomValidator.Nickname | |
}, | |
methods: { | |
validateBeforeSubmit(event) { | |
this.$validate() | |
.then(function(success) { | |
if(!success) | |
event.preventDefault(); | |
}) | |
} | |
} | |
}); |
This file contains 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 { Validator } from 'simple-vue-validator' | |
const PATTERN = { | |
MONEY: /(^[+-]?\d+)(\d{3})/, | |
USERNAME: /^[a-zA-Z0-9]{4,20}/, | |
PASSWORD: /^.*(?=.{5,15})(?=.*\d)(?=.*[a-z|A-Z]).*$/ | |
} | |
export function Username(value) { | |
return Validator.value(value) | |
.required('* Username is required') | |
.regex(PATTERN.USERNAME, 'Alphabet/Number in a 4-20 Characters') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment