Sunday, 24 May 2015

Jquery validation page 1

<?php   ob_start(); ?>
<script type="text/javascript">

function _(x)
{
    return document.getElementById(x);
}

function validate1()
{
    if (isEmail1() && ispass1())
        if (confirm("\n You are about to add new Customer. \n\nPress Ok to submit. Cancel to abort."))
        {
            return true;
        }
        else        {
            alert("You have chosen to abort .");
            return false;
        }
    else        return false;
}
function ispass1()
{
    var pin=_("pass").value;

    var len=_("pass").value.length;

    //alert(len);    if(pin=="" || len<8 )
    {
        _("errpass1").innerHTML="Enter min 8 digit mobile number";
        _("pass").style.borderColor = "red";
        return false;
    }
    else    {
        _("errpass1").innerHTML=" ";
        _("pass").style.borderColor = "grey";
        return true;
    }
}
function isEmail1()
{
    var mail=_("username").value;
    var regExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[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,}))$/;

    if(mail=="" || !regExp.test(mail))
    {
        _("erremail1").innerHTML="Please enter valid E-Mail";
        _("username").style.borderColor = "red";
        return false;
    }
    else    {
        _("erremail1").innerHTML=" ";
        _("username").style.borderColor = "grey";
        return true;
    }
}





function validate()
{
    if (isFirstname() && isLastname() && isAddress() && isAddress1() && ispincode() && isEmail() && ispincode() && ispass() && isMobile()
    && isMobile1() && isCountry() && isst() && isct())
        if (confirm("\n You are about to add new Customer. \n\nPress Ok to submit. Cancel to abort."))
        {
            return true;
        }
        else        {
            alert("You have chosen to abort .");
            return false;
        }
    else        return false;
}

function isFirstname()
{
    var firstname=_("fname").value;
    var regExp = /^[a-z A-Z]*$/;

    if(firstname=="" || !regExp.test(firstname))
    {
        _("errfirstname").innerHTML="Please enter valid Firstname";
        _("fname").style.borderColor = "red";
        return false;
    }
    else    {
        _("errfirstname").innerHTML=" ";
        _("fname").style.borderColor = "grey";
        return true;
    }
}

function isLastname()
{
    var lastname=_("lname").value;
    var regExp = /^[a-z A-Z]*$/;

    if(lastname=="" || !regExp.test(lastname))
    {
        _("errlastname").innerHTML="Please enter valid Lastname";
        _("lname").style.borderColor = "red";
        return false;
    }
    else    {
        _("errlastname").innerHTML=" ";
        _("lname").style.borderColor = "grey";
        return true;
    }
}

function isAddress()
{
    var address=_("addr").value;

    if(address=="")
    {
        _("erraddress").innerHTML="Please enter address";
        _("addr").style.borderColor = "red";
        return false;
    }
    else    {
        _("erraddress").innerHTML=" ";
        _("addr").style.borderColor = "grey";
        return true;
    }
}
function isAddress1()
{
    var address=_("addr1").value;

    if(address=="")
    {
        _("errshipadd").innerHTML="Please Enter Shipping Address";
        _("addr1").style.borderColor = "red";
        return false;
    }
    else    {
        _("errshipadd").innerHTML=" ";
        _("addr1").style.borderColor = "grey";
        return true;
    }
}
function ispincode()
{
    var pin=_("txtzip").value;
    var regExp =/^[0-9]*$/;
    var len=_("txtzip").value.length;

    //alert(len);    if(pin=="" || !regExp.test(pin) || len!=6 )
    {
        _("errpin").innerHTML="Enter 6 digit mobile number";
        _("txtzip").style.borderColor = "red";
        return false;
    }
    else    {
        _("errpin").innerHTML=" ";
        _("txtzip").style.borderColor = "grey";
        return true;
    }
}
function isEmail()
{
    var mail=_("email").value;
    var regExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[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,}))$/;

    if(mail=="" || !regExp.test(mail))
    {
        _("erremail").innerHTML="Please enter valid E-Mail";
        _("email").style.borderColor = "red";
        return false;
    }
    else    {
        _("erremail").innerHTML=" ";
        _("email").style.borderColor = "grey";
        return true;
    }
}
function ispass()
{
    var pin=_("pass").value;

    var len=_("pass").value.length;

    //alert(len);    if(pin=="" || len<8 )
    {
        _("errpass").innerHTML="Enter min 8 digit mobile number";
        _("txtpass").style.borderColor = "red";
        return false;
    }
    else    {
        _("errpass").innerHTML=" ";
        _("pass").style.borderColor = "grey";
        return true;
    }
}

function isMobile()
{
    var mobile=_("txtmo").value;
    var regExp =/^[0-9]*$/;
    var len=_("txtmo").value.length;

    //alert(len);    if(mobile=="" || !regExp.test(mobile) || len!=10 )
    {
        _("errmo").innerHTML="Enter 10 digit mobile number";
        _("txtmo").style.borderColor = "red";
        return false;
    }
    else    {
        _("errmo").innerHTML=" ";
        _("txt_mo").style.borderColor = "grey";
        return true;
    }
}
function isMobile1()
{
    var mobile=_("txtpho").value;
    var regExp =/^[0-9]*$/;
    var len=_("txtpho").value.length;

    //alert(len);    if(mobile=="" || !regExp.test(mobile) || len!=10 )
    {
        _("errpho").innerHTML="Enter 10 digit mobile number";
        _("txtpho").style.borderColor = "red";
        return false;
    }
    else    {
        _("errpho").innerHTML=" ";
        _("txtpho").style.borderColor = "grey";
        return true;
    }
}



function isCountry()
{

    var country=_("co").value;

    if(country=="")
    {
        _("errcountry").innerHTML="Please select Country";
        _("co").style.borderColor = "red";
        return false;
    }
    else    {
        _("errcountry").innerHTML=" ";
        _("co").style.borderColor = "grey";
        return true;
    }

}

function isst()
{

    var state=_("st").value;

    if(state=="")
    {
        _("errst").innerHTML="Please select State";
        _("st").style.borderColor = "red";
        return false;
    }
    else    {
        _("errst").innerHTML=" ";
        _("st").style.borderColor = "grey";
        return true;
    }

}
function isct()
{

    var city=_("ct").value;

    if(city=="")
    {
        _("errct").innerHTML="Please select City";
        _("ct").style.borderColor = "red";
        return false;
    }
    else    {
        _("errct").innerHTML=" ";
        _("ct").style.borderColor = "grey";
        return true;
    }

}

</script>

No comments:

Post a Comment