0

I need to validate:

  1. A textfield which is for phone and price. How can I remove the two button at the right of the textfield? Those are to higher or lower the value. I do not need them. Also if the phone begins with 0 then it get messy and red.

  2. A textfield which is for the name. Allow only A-Z,a-z,space.

Edit* I dont know why my code doesnt appear here on stackoverflow. http://jsfiddle.net/instajsf/LbYVK/

1 Answers1

0

I'm going to guess that the up/down buttons you see on the entry fields are put in by your user agent (Web browser). Under Chrome, I see nothing.

As for the second part of your question, there are many, many, many posts about how how to validate user input.

A search for "javascript alphanumeric" brought this up as my first result: RegEx for Javascript to allow only alphanumeric

If you are going to be sending this data to the server, don't forget that you must validate server side as well. Nothing that comes from the client may be trusted.

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • Thanks for the answer. :) I also use chrome! but on mac. Any idea on how to fix the phone numbers starting with 0? –  Sep 09 '12 at 20:37
  • Sure! Phone numbers aren't integers! They are strings! – Jeremy J Starcher Sep 09 '12 at 20:39
  • Oh now I understand. I just add another regEx for the numbers for that field. Thank you. –  Sep 09 '12 at 20:39
  • regEx works ... but you have to consider your local customs too. For instance, int the USA our phone numbers follow this pattern `(###) ###-####` or some variation of that grouping. To play with an example phone number `555-555-1212` looks like a phone number to the American eye, but if you write it `5555551212` we won't see a phone number there. Considering your local customs for writing out numbers and be sure to include/allow them too. – Jeremy J Starcher Sep 09 '12 at 20:44
  • (My personal approach -- I let the user enter anything in that field, then I strip out everything BUT the numbers -- then I reformat the number so it looks write, then put it back in.) – Jeremy J Starcher Sep 09 '12 at 20:45