March 28, 2015

Restrict the users to type certain number of characters in a HTML Text Box

In your web development career every one frequently come across a situation where you need to restrict the users to enter a certain number characters in your text boxes or text areas. Again the best example is when you are taking persons phone number. You can accomplish this task in so many ways either with JavaScript or HTML or with other libraries but, the easy way is to use just a simple HTML attribute that's what we will see in this tutorial.

<input type="text" maxlength="10" />

There are other useful attributes to be discussed. Let's see about disabled attribute. 

<input type="text"  value="Hello" disabled />

disabled is used to make the user restrict from changing the value from the text box for example country code for the particular country is fixed. You can also use this disabled attribute in side buttons and you can control it with JavaScript for certain functionalities.

<input type="text"  value="Hello" required/>

Required attribute is used to tell the user it is compulsory to fill the text box before submitting the form.

<input type="text"  value="Hello" placeholder="Enter some value"/>

Placeholder is used to give the users a hint about what type of value to be filled inside a particular text box.

So, this is it for this tutorial. There are many attributes that can be used inside form elements I suggest you to explore them. If any queries feel free to post a comment below or mail me @ ething4pc@gmail.com 


No comments: