View Full Version : Need to create error message when user enters an underscore

March 16th, 2012, 05:06 AM

I need to create a rule in a FusionPro template that will create an error message (customized) when a user enters an underscore in a text form field in the store.

We would like to find a way to prevent a user from typing underscores in a text field (for a URL). Or is there an alternate method?

I don't want to replace the underscore with another character and just adding a note is not going to be sufficient.

Thank you!

March 16th, 2012, 08:35 AM
How about something like this?

var s = Field("YourFieldHere");

return (s.indexOf("_") != -1) ? "<color name=\"Red\">This form can not contain underscores</color>" : s;

March 16th, 2012, 01:08 PM
Assuming you are using MarcomCentral you can put this in the Note field. It will probably need some tweaking to get the desired effect.

<script type="text/javascript">

//This needs to match the <input id= of the field that the url is entered in.
var field_id_name = "Website";

//Put your warning message in here
var alert_message = "Don't do this!";

document.getElementById(field_id_name).onkeyup = alert_box;

function alert_box()
var s = this.value.indexOf("_");
if (s > -1)

//This strips out the underscore after they type it in
this.value = this.value.substring(0,s)