javascript validations for email,phone/mobile

javascript validations for email,phone/mobile

Introduction :

Javascript and jquery validation are client side so it can decrease the server load unless using the client side validation it is faster than the server validation like asp.net, in this tutorial explain client validation like mobile validation,Email validation,pasword with regular expresion,and required field validator etc.

        var stUserName = document.getElementById("txtUserName").value;
        var stPassword = document.getElementById("txtstPassword").value;
        var stEmailId = document.getElementById("txtEmailId").value;
        var stContactNo = document.getElementById("txtContactNo").value;
        var confirmPassword = $("#txtConformPwd").val();

        var ContactNo = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
        var name = /^[A-Za-z0-9 ]{3,20}$/;
        var emailReg = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     
        if (stUserName == "") {
            ShowError("Please Provide UserName");
            return false;
        }
        else if (!stUserName.match(name)) {
            ShowError("White space is not allowed.");
            return false;
            }

        if (stPassword == "") {
            ShowError("Please Provide Password");
            return false;
        }
        if (stPassword != confirmPassword) {
            ShowError("Confirm Password do not match.");
            return false;
        }
        if (!(stEmailId).match(emailReg)) {
            ShowError("Invalid Email...!!!!!!");
            return false;
        }

        if (stContactNo == "") {
            ShowError("Please Provide ContactNo");
            return false;
        }
        else if (!(stContactNo).match(ContactNo)) {
            ShowError("Not a valid Phone Number");
            return false;

        }


See Other Tutorial :

AngularJS CRUD Operation : Select Insert Edit Update and Delete using AngularJS in ASP.Net MVC

*  AngularJS With ASP.NET MVC

*  Convert Rows to columns using 'Pivot' in SQL Server

*  Mvc Registration page With user exist using Ajax method

*  MVC 4 How to Perform Insert Update Delete Edit Select Operation

*  MVC4 Edit,update,Delete,cancel inside gridview using sql database


*  MVC 4 Gridview To Display Data Using SQL Server Database With Simple code


*  Login page in asp.net Mvc4 Web application


*  Mvc4 How to bind Dropdown List using Sql Database


Gridview find control in asp.net
Previous
Next Post »