2

I have a text field for which I wrote add error methods like it can be only numeric and cannot be less than 5 characters.. Is there anyway that I could display error messages as soon as user starts typing in the text field.

1

You have this tagged with Visualforce so I am assuming you plan to create your own Visualforce page to do this. (To do it using normal layout-based UI requires some fairly nasty sidebar Javascript.)

Essentially you will have to repeat your validation in Javascript. It is normal to use something like jQuery.keyup to abstract away browser differences and make your code simpler. And then you also have to decide how to report the error- typically this would be by inserting HTML near the field and changing some colors. So if this is all new technology to you it will be non-trivial to get working.

(You could also choose to do it by using Visualforce's partial page refresh mechanism but in my experience this is so slow that it just confuses your users.)

If you were lucky enough to only have to support very modern browsers you can make use of the HTML5 input pattern feature (see e.g. http://html5pattern.com/). You can specify this in Visualforce by prefixing the attribute with "html-".

PS If you want to do a lot of jQuery form validation you might also choose to use the jQuery Validation Plugin; Wes Nolte has a blog post Salesforce Form Validation Enhanced about using this with Visualforce.

-1

Maybe this post might help you as well. Basically in javascript (onkeyup), you can replace all characters, except numeric, by ''.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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