client side validations in .NET Web Applications with JavaScript/jQuery

2

 

(In order to Enlarge images Please Right Click and Open images in New Tab).

Description—

You can refer:

http://www.c-sharpcorner.com/blogs/client-side-validations-in-net-web-applications-with-javascript-jquery

Now we will learn how to perform validations at client side with the help of JavaScript/jQuery.

Main Advantages of this approach is

  • We can be able to improve the performance of our web application since it runs in browser itself and it is quick as well.

 

In this article I will demonstrate,

1) How to validate alphanumeric entry in input textbox

  • For this purpose use isAlphaNumericContents() which is mentioned below

2) How to validate decimal values entry in input textbox

  • For this purpose use CheckValidDecimalAmount () which is mentioned below

 

3) How to validate email id entry in input textbox

  • For this purpose use validateUpdatedEmail () which is mentioned below

 

Now let us see  with code snippets

  function isAlphaNumericContents(strContents) {

        var cde, i, l;

        for (i = 0, l = strContents.length; i < l; i++) {

            cde = strContents.charCodeAt(i);

            if (!(cde > 47 && cde < 58) &&

                !(cde > 64 && cde < 91) &&

                !(cde > 96 && cde < 123)) {

                return false;

            }

        }

        return true;

    };

function CheckValidDecimalAmount(amountPaid) {

        if (!(/^[-+]?\d*\.?\d*$/.test(amountPaid))) {

            return false;

        }

        return true;

    }

function validateUpdatedEmail (updatedEmailID) {

        var regexInfo = /^(([^<>()\[\]\\.,;:\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,}))$/;

        return regexInfo.test(updatedEmailID);

    }

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s