Vuejs Form Validation Example – vue validation

Vuejs Form Validation Example – vue validation

Welcome on infinityknow.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Vuejs Form Validation Example – vue validation

In this post we will show you Best way to implement Template-Based Form Validation With Vue.js and vee-validate, hear for How to vuejs form validation on submit – vue validation with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

External include libs

At First of all you need to External include the jQuery CDN or library.

<a href="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js</a>
<a href="https://cdn.jsdelivr.net/vue.validator/2.1.3/vue-validator.min.js">https://cdn.jsdelivr.net/vue.validator/2.1.3/vue-validator.min.js</a>

vue-validator Loading the plugin Vuejs Form Validation Example

Sample – create user form

READ :  custom ng-template Directive using AngularJS Examples

Vue.use(VueValidator)
All fields are simple more mandatory
and second one Email format
If password strong is long enough
If both simple version of the more provided uniq password are the same
And possibly many other checks as like user does not any exist or your password new format but I any won’t go through level these ones here

	<form>
    <p>
        <label>your Username</label>
        
    </p>
    <p>
        <label>your Password</label>
        
    </p>
    <p>
        <label>your Confirm password</label>
        
    </p>
    <p>
        
    </p>
</form>

In order to use plugin using vuejs vue-validator plugin, the form some needs to be versions surronded by a vuejs “””” tag and with one more any data wrapper to call using VueJS it becomes:

READ :  Vuejs Form Validation using Laravel with PHP

Create Form using Vuejs

<div id="liveForm">
    
        <form>
            ...HTML Form elements
        </form>
    
</div>

    new Vue({
        el: "#liveForm"
    });

Adding validations




REGX some rules of vuejs check validate using vuejs function

Vue.validator('email', function (val) {
  return /^(([^()[]\.,;:\[email protected]\"]+(.[^()[]\.,;:\[email protected]\"]+)*)|(\".+\"))@(([[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,}))$/.test(val)
})

script using validation

    new Vue({
        el: "#liveForm",
        data: {
            password: '';
        }
        validators: {
            livepasscheck: function(val) {return true;}
        }
    });


livepasscheck: function(val) {
    return val == this.vm.password;
}

Display errors to the user

	// all the applay using vuejs query string
    $validator.email.required // must
    $validator.email.email  // email check
    $validator.email.checkUserExists

v-if condition and check to error

	
<p>simple Provide an email must</p>
<p>Please your provide a valid new email adress</p>
<p>This email is alredy already in use</p>
<p>Please provide a your valid email adress</p>

Types of error generated

valid: when all data validations of the HTML field are successful submit
invalid: when at least using vuejs one validation fails
untouched: field has uniq not been any data focused yet
touched: field had the simple focus and focus any more moved to another HTML field

READ :  Laravel vuejs form validation - Input Validation with Laravel

error css message

	
	.invalid.untouched ~ .error {
    display: none;
}

Example

I hope you have Got vuejs form validation error message And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Add a Comment

Your email address will not be published. Required fields are marked *