All Type Coding

Search Here

Alphabets validation in javascript

For Dynamic control
function isCharKey(obj, evt) {
            var ctrl = obj.id;
            var charCode1 = evt.which;
            if (charCode1 > 31 && charCode1 != 32 && charCode1 != 45 && (charCode1 < 65 || charCode1 > 90) && (charCode1 < 97 || charCode1 > 122)) {

                alert("Please enter alphabets only");

                $('#' + ctrl).focus();

                // $('#' + ctrl).val('');
                return false;
            }
            return true;
        }

For static control

 function isalphanumneric(e) {
            var keynum;

            keynum = e.keyCode ? e.keyCode : e.which;
            //  alert(keynum);
            if ((keynum < 65 || keynum > 90) && (keynum < 97 || keynum > 122) && (keynum != 8 && keynum != 9) && keynum != 46 && keynum != 37 && keynum != 39 && keynum != 32) {
                e.preventDefault();
                alert('Please enter alphabets only');
                return false;
            }

            return true;

        }

No comments :

Post a Comment