By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,805 Members | 1,349 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,805 IT Pros & Developers. It's quick & easy.

How to validate jsp (numeric) field on copy/paste?

P: 24
Hi guys,
I am developing an application which takes consumer_id from our employees and searches them from database if consumer_id match is found his details are available...

Now I have managed to validate the text field to numeric It will accept numbers only..If anyone presses alphabets or special characters it wil not type in the filed...
Once consumer_id is entered and find is clicked it will search through database & if match is found it will display details of consumer or if no match is found it will throw an alert and return to homescreen..

Problem occurs when I copy paste.. If I copy paste still works.If wrong consumer_id(nos. only) is pasted it still throws alert..

But if I copy/paste alphabets or special characters with/without nos... It gives Sql exception error...

Now I cannot disable copy/paste it is required bcoz consumer_id is 7 digit and it will be provided to them via email to check....

I also know I have to create a function for validating copy/paste and call it onblur/onchange/onsubmit...
But I don't know how to start or how to validate it..nothing comes to mind...

Although our staff is not stupid enough to enter alphabet/special characters in the id field but it does look pathetic from apllication development point of view... Imagine in gmail if you tried using * in username and it gave you exception error...
Jun 3 '13 #1
Share this Question
Share on Google+
3 Replies

P: 13,264
Client side validations are great because they give the user quick feedback but you should also have server side vaidations which check the values before invoking your data access layer.
Jun 11 '13 #2

P: 24
There is server side validation...
But software requirement states client side validation to reduce server load and to save time(although negligible..)
Jun 11 '13 #3

P: 13,264
If there is server side validation then why do you get an SQL error on the page? The server side validation should have stopped the SQL from being executed at all if the values are not correct.

You can't have client side validations only if you are want to be 100% sure because you can't cater for all different client configurations (as you are seeing now). e.g Some users may have Javascript turned off and some people may not access your site through a browser at all (direct http calls from some server side language).
Jun 12 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.