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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shepard
    New Member
    • Feb 2013
    • 24

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

    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 only..ie: 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 nos...it 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...
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    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.

    Comment

    • Shepard
      New Member
      • Feb 2013
      • 24

      #3
      There is server side validation...
      But software requirement states client side validation to reduce server load and to save time(although negligible..)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        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).

        Comment

        Working...