Here i will share some useful jQuery validation properties and functions with you, like counting the length of an element, allowing alphanumeric and numbers only values to an input element.

1- Count length of an input box value ?

$(id).val().length

jQuery length property is use to calculate the total element in the jQuery object.

Example

when you focus out of the input box checklength() function calculate the length of your input box value and retrun you in alert box.

 

2: Check alphanumeric value

when you focus out of the input box, the above function match your input box value with the defined regular expression “/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+[0-9a-z]+$/i;”. if it will match with it, it return you true otherwise alert box.

 

3: Allow numbers only to an input field

key 57 is the code of number 9 and key 48 is the code of number 0, so it check that the press key is greater than 9 and less than 0, it returns a alert box with the defined message.

4: How to check blank space

key 32 is the code of space key , so it check that the press key code is equal to 32, it returns a alert box with the defined message.

 

So Guys if feel any problem with these functions, you can leave it on comment. I will try to reply you and thank you to read our blog. Keep visiting