Take the 2-minute tour ×
User Experience Stack Exchange is a question and answer site for user experience researchers and experts. It's 100% free, no registration required.

I have a form that only takes in numbers as it represents a dollar amount. Currently, the form only accepts numerical keystrokes. Is this good practise?

share|improve this question
1  
Currently the user can get around it by using pasting other values in the form. Also, this is breaking keyboard shortcuts like Ctrl-V, but I am working to fix these issues. I am also aware that data should be verified on the server –  Casebash Sep 19 '11 at 7:28
    
Actually if validation is that simple it should be validated with Javascript on the client (then at the server in case someone sends raw data/with JS disabled.) JS also lets you give immediate feedback if they enter an invalid character. It's definitely NOT good usability to let them accidentally enter '!00' in a number only field, then make them re-enter it –  Ben Brocka Sep 19 '11 at 11:55
3  
also if breaking copy/paste is an issue (say they copy "$30" and you need "30") you can have Javascript on the form dynamically trim out the non-numerical values, and maybe show a little helper text stating that non-numeric values were removed. –  Ben Brocka Sep 19 '11 at 12:34
    
@BenBrocka: I meant verified on the server in addition to the client –  Casebash Sep 19 '11 at 12:36
add comment

4 Answers

up vote 7 down vote accepted

Yes, I would say that you should only accept characters appropriate to the field. If it's a phone number, you should also accept characters like: ()-+.

However, you should let the person know that an invalid key was pressed rather than do nothing. Otherwise you may end up frustrating them. Examples include: a small error message that pops up next to the field and then fades out; or simply changing the border colour to red before fading it back again.

share|improve this answer
2  
I would advise caution on assuming you know all the valid characters for a particular field. In a phone number field, is it bad data to write "0123 456 (ask for extension 19)"? Or "Call patient's daughter: 0987 654"? –  vincebowdren May 10 '13 at 9:06
1  
@vincebowdren Good point for phone numbers, but that wasn't the op's question. He was referring to dollar input (which would typically need to be ready and manipulated programatically). –  JohnGB May 10 '13 at 12:21
2  
Agreed. But it's worth considering the purpose to which any data item will be put, before deciding on validation rules. A dollar value might be net or gross, might be per item or by weight, might be debit or credit (any of which might affect the way the user thinks they should be entering the data). What sounds like a simple issue might have complex requirements and subtle use cases - which the OP should think through whatever kind of field they are thinking of validating. –  vincebowdren May 10 '13 at 12:31
add comment

Short answer: Yes, I believe this is indeed good practice. Mind that the decimal sign (possibly depending on localization settings) or a negative sign might also be regarded as correct input.

Also check out this article: http://msdn.microsoft.com/en-us/library/windows/apps/aa511451.aspx#passwordsAndPINs especially the part about "Incorrect character".

share|improve this answer
add comment

Client-side validation can be helpful, but you need to be very careful how you implement it; it's easy to make it unhelpful to the user.

For example, if you silently ignore non-numeric characters, then a user quickly typing '12.34' might not realise that the field has ignored their decimal point and accepted the text as '1234'.

Another example; if you silently ignore non-numeric characters, then a user typing in a negative number '-56' will find it converted into a positive number '56'.

Now, it may well be invalid for the system to accept fractional numbers or negative numbers; but you need to think how to best help the user when they enter these. Are they deliberately trying to enter a value they believe to be valid? Are they accidentally typing a value which they know to be invalid? Does your validation routine help the user realise and correct their mistake?

share|improve this answer
    
The most sensible answer to date. Too much validation kills validation. –  Nicolas Barbulesco May 10 '13 at 9:01
add comment

Like @Bart, I thought to the decimal separator : “,” or “.”

It may be a good idea to accept the signs “+” and “−”, and “-” of course [“−” is a “minus” sign, and “-” is a hyphen].

The same goes for the space, and some of its variants : non-breaking space, thin space… When I want to transfer 1 million dollars, I type “1 000 000”.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.