-4

I have a textBox1 which should take Fixed Format like eg below

HH:MM:SS or ::__

where HH,MM,SS can be entered but colon(:) should be fixed.Please help me out.

shal
  • 47
  • 1
  • 5
  • 2
    why not a masked textbox like this [thread](http://stackoverflow.com/questions/12578507/how-to-implement-an-input-with-a-mask)? – sujith karivelil May 03 '17 at 11:16
  • Is this ASP.NET Forms, or MVC? Either way, you could use a regular expression to check the format quite easily. e.g. `^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$` should work. If it's Forms, use a RegularExpressionValidator control along with the textbox to define it. If it's MVC use a Data Annotation Validator on the field in the ViewModel. – ADyson May 03 '17 at 11:20

2 Answers2

0

You Can use Mask plugin , i think it will serve you see this link https://igorescobar.github.io/jQuery-Mask-Plugin/

download it from here https://github.com/igorescobar/jQuery-Mask-Plugin

Ammar Mousa
  • 48
  • 10
  • this is futile without corresponding server-side validation. It's fine for enhancing the user experience, but cannot be a substitute for properly validating the input on the server - anything client-side can be bypassed or disabled by malicious users or bots. – ADyson May 03 '17 at 13:45
0

look at this:

new Formatter(document.getElementById('date-input'), {
'pattern': '{{99}}/{{99}}/{{9999}}',
'persistent': true
});

or

$('#date-input').formatter({
'pattern': '{{99}}/{{99}}/{{9999}}',
'persistent': true
});
Therichpost
  • 1,759
  • 2
  • 14
  • 19