﻿/*---------------------*/
/* Developed by Anshul */
/*    Version: 1.0     */
/*---------------------*/


/* This javascript file contains some javascript functions 
    through which a developer can validate text boxes and input boxes very easily. */
    
/* A developer can append more functions according to the requirements. */

/* CODE START --------------*/

/* 1.) This function will not allow ' and ; in the text box. These 2 characters are mostly used 
    for sql injection */

/*function notAllowSpecialCharacters(e)
        {
      
            // Get the ASCII value of the key that the user entered
            var key = (document.all)?window.event.keyCode:e.which;
            alert(key);
            if ((key == 39) || (key == 59) || (key == 32))
                // If it was, then dispose the key and continue with entry
                return false;
            else
                // If it was, then allow the entry to continue
                return true; 
        }*/
        
        function notAllowSpecialCharacters(e) 
        {                        
            
            var keycode = (document.all)?window.event.keyCode:e.which;
            //alert(keycode);
            if((keycode >= 47 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) ||  (keycode == 8) || (keycode == 46) || (keycode == 36) || (keycode == 190) || (keycode == 9) || (keycode == 32) || (keycode == 39) || (keycode == 37) || (keycode == 191) || (keycode == 35) || (keycode == 186) || (keycode == 0) || (keycode == 43) || (keycode == 45)) 
            {
                return true; 
            }
            else
            {
                return false; 
            }

            return true; 
        }


/* 2.) This function will allow only alphabetical characters and spaces. */
        
        function allowOnlyAlphabet(e)
        {
            // Get the ASCII value of the key that the user entered
            var key = (document.all)?window.event.keyCode:e.which;
                   
            if ((key >= 65 && key <= 90 ) || (key >= 97 && key<= 122) || (key == 8) || (key == 32)|| (key == 0))
                // If it was, then allow the entry to continue
                return true;
            else
                // If it was not, then dispose the key and continue with entry
                return false; 
        }
        
/* 3.) This function will allow only numeric values with no spaces */

        function allowOnlyNumber(evt)
        {
            // Get the ASCII value of the key that the user entered
            var charCode = (evt.which) ? evt.which : event.keyCode
           
                if ((charCode >= 48 && charCode <= 57 ) || (charCode == 8) || (charCode == 0))
                    // If it was, then allow the entry to continue
                    return true;
                else
                    // If it was not, then dispose the key and continue with entry
                    return false;      
        }
        
/* 4.) This function will allow only float/double values with no spaces */

        function allowOnlyFloatNumber(evt)
        {
            // Get the ASCII value of the key that the user entered
            var charCode = (evt.which) ? evt.which : event.keyCode
                if ((charCode >= 48 && charCode <= 57 ) || (charCode == 8) || (charCode == 46) || (charCode == 0))
                    // If it was, then allow the entry to continue
                    return true;
                else
                    // If it was not, then dispose the key and continue with entry
                    return false;  
        }
        
/* 5.) This function will allow alphabetical characters, numeric values and spaces. */
        
        function allowAlphabetAndNumer(e)
        {
            // Get the ASCII value of the key that the user entered
            var key = (document.all)?window.event.keyCode:e.which;
            
            if ((key >= 65 && key <= 90 ) || (key >= 97 && key<= 122) || (key >= 48 && key<= 57) || (key == 8) || (key == 32)|| (key == 0) || (key == 45))
                // If it was, then allow the entry to continue
                return true;
            else
                // If it was not, then dispose the key and continue with entry
                return false; 
        }
        
/* 6.) This function will not allow anything. 
    It will be used in the date text boxes where no input will be taken from the user. 
    Here the user will click on the calenadr control only */

        function notAllowAnything(e)
                {
                    // Get the ASCII value of the key that the user entered
                    var key = (document.all)?window.event.keyCode:e.which;
                       return false;
                }
        
/* 7.) This function will not allow ' and ; and space in the text box. These 2 characters are mostly used 
    for sql injection */

        function ntalw(e)
                {
                    
                    // Get the ASCII value of the key that the user entered
                    var key = (document.all)?window.event.keyCode:e.which;
                    //alert(key);
                    if ((key == 39) || (key == 32) || (key == 59))
                    {
                        // If it was, then dispose the key and continue with entry
                        return false;
                        }
                    else
                        // If it was, then allow the entry to continue
                        return true; 
                }

/* 8.) This function will allow alphabetical characters, numeric values with no spaces. */
        
        function allowAlphabetAndNumerN(e)
        {
            // Get the ASCII value of the key that the user entered
            var key = (document.all)?window.event.keyCode:e.which;
            
            if ((key >= 65 && key <= 90 ) || (key >= 97 && key<= 122) || (key >= 48 && key<= 57) || (key == 8) || (key == 0) || (key == 45))
                // If it was, then allow the entry to continue
                return true;
            else
                // If it was not, then dispose the key and continue with entry
                return false; 
        }
         
/* CODE END ---------------*/