How to shorten Javascript variable check?
How to shorten Javascript variable check?
Author
Discussion

selwonk

2,143 posts

257 months

Wednesday 6th December 2017
quotequote all
Is there a specific reason you are not using MAXLENGTH in the INPUT declarations?

hyphen

26,262 posts

122 months

Wednesday 6th December 2017
quotequote all
Why have you gone to the trouble of self-written length checking code? Wouldn't it make more sense to use a pre-built validation library.

hyphen

26,262 posts

122 months

Wednesday 6th December 2017
quotequote all
With most common tasks in web programming, others have already written it before. So rather than writing yourself and then testing it all, it is often more efficient to use something that is tried and trusted.

If you are using a framework of any kind then that will probably have validation built in, otherwise you can look at a separate javascript library.

You can also use HTML5 inbuilt features, for example
Maxlength: http://jsfiddle.net/xhqsB/1432/
input patterns: http://jsfiddle.net/xhqsB/1433/

Edited by hyphen on Wednesday 6th December 15:46