Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User is free to enter any thing in datepicker text box. #46

Open
rakeshy3 opened this issue Jun 5, 2019 · 1 comment
Open

User is free to enter any thing in datepicker text box. #46

rakeshy3 opened this issue Jun 5, 2019 · 1 comment

Comments

@rakeshy3
Copy link

rakeshy3 commented Jun 5, 2019

User is free to enter any thing in datepicker text box. it should only allow to enter date in chosen format and date only not any text. Please suggest how I can achieve this.

@barlowm
Copy link

barlowm commented Jun 27, 2019

I've seen that as well (on MOST of the date pickers that use a text field.)
I added my own handler to trap that:

$('#date').keydown(function(e) {
	const validKeys = /[0-9\.\-\/]/;
	 if((e.key.match(validKeys))) {
		return true;
	 }
	 else {
	 	return false;
	 }
})

This allows only numbers and "-" or "/" or "." as separators (so you can enter dates as "01/01/2001" or "01-02-2002" or "01.03.2003")
It doesn't trap for all possible errors (like entering "/1.2-3") but that can be done as well. I just validate (using moment) on blur of the field.

Now granted that type of input validation could (and really should) be done as part of the module. I just don't have the time to make a PR for it at the moment.

Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants