Is there a way to limit a text field to just text and numbers? I have a comments field in a form that is stored in a variable as multiple lines of text and then the text is sent in an email. I believe the variable did not populate based upon some of the special characters entered.
Yes. You can do it. but only for a multiline text field with Plain Text.
1. Just assign control id your comment field as shown in below screen
2. Then add following script in custom javascript:
NWF.FormFiller.Events.RegisterAfterReady(function () {
var ctrlComment = NWF$("#" + ctrlID_Comment);
if(ctrlComment){
NWF$(ctrlComment).keypress(function (e) {
var regex = new RegExp("^[a-zA-Z0-9s]+$");
var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
if (regex.test(str)) {
return true;
}
e.preventDefault();
return false;
});
}
});
I just allowed text and number. You can also change regular expression according to your requirement.
Let me know if you want sample form for this.
Hope it will help
Hi, thanks for the information. I think the characters that are causing the text not to show are [ and ]. Is there a listing of the characters that might cause the error in setting the variable other than these 2 characters? Also, is there a way to not allow these characters but allow all others (so I guess it would almost be the opposite of what you have)? Thanks again.
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.