Date Mask Text Field using only HTML,JavaScript

Placeholder
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).

I have used Regular Expression.I am checking if 2 digits are entered if yes i have appened a slash.

<input 
	type="text" 
	name="date" 
	placeholder="dd/mm/yyyy" 
	onkeyup="
		var v = this.value;
		if (v.match(/^\d{2}$/) !== null) {
			this.value = v + '/';
		} else if (v.match(/^\d{2}\/\d{2}$/) !== null) {
			this.value = v + '/';
		}"
	maxlength="10"
>
Advertisements

One thought on “Date Mask Text Field using only HTML,JavaScript

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