Prevent ?*() from Form Field Submissions

Anonymous
Not applicable

Prevent ?*() from Form Field Submissions

Is there an out of box way to delete or not allow characters such ?, *, (, ), etc. from entering form fields? I'm receiving SFDC sync errors due to individuals accidentally typing these characters in error when submitting our form.

4 REPLIES 4
Josh_Hill13
Level 10 - Champion Alumni

Re: Prevent ?*() from Form Field Submissions

You would need to add javascript to the page/form to do this.

Casey_Grimes
Level 10

Re: Prevent ?*() from Form Field Submissions

Hi Kaitlin,

This is possible, but you're going to need to use a little bit of JavaScript. That being said, you have a few different options (as always.) I'd recommend going the lazy route and adding jQuery alphanum. You would just need to add <script>$(".mktoField").alphanum();</script> to your pages after embedding jQuery and alphanum.

SanfordWhiteman
Level 10 - Community Moderator

Re: Prevent ?*() from Form Field Submissions

You would just need to add <script>$(".mktoField").alphanum();</script> to your pages after embedding jQuery and alphanum.

(Well, you'd actually need to put this in the form's onReady/whenReady or else there's a race condition.)

SanfordWhiteman
Level 10 - Community Moderator

Re: Prevent ?*() from Form Field Submissions

Do you really want to stop people from entering these characters, or do you want to stop those characters from posting to Marketo (and therefore to SFDC)?

I don't know what fields you're planning on restricting, but I feel it violates least astonishment to stop people from typing characters that are not, in fact, always typos.  In a Last Name field, apostrophes and hyphens need to be allowed, and if people add a suffix ("Jr.") in a Last Name textbox, you also need to allow spaces and periods.  Companies include "E*Trade" and others with question marks and exclamation marks.  If your back end can't handle these characters, maybe it's the back end that needs to be fixed?  Or else you can silently strip the characters in the form's onSubmit.  I think it's a better user experience to let people enter what they know to be legitimate information.

(On a related note, few things drive me as crazy as undocumented, arbitrary length limits on email fields.  I'll tell you what my email address is, you don't tell me!)