I have a textfield that the user types in a part number. I want to prevent them from having a space in any part of the part number they enter. If they enter a space anywhere in the part number, an error message appears telling them to use an underscore (_) instead of a space.
How do I script this in JavaScript?
Solved! Go to Solution.
Views
Replies
Total Likes
Put this in the change event of the field:
if (xfa.event.change==" "){
xfa.host.messageBox("No spaces allowed");
xfa.event.change="";
}
or even try this:
if (xfa.event.change==" "){
xfa.event.change="_";
}
Kyle
Views
Replies
Total Likes
Put this in the change event of the field:
if (xfa.event.change==" "){
xfa.host.messageBox("No spaces allowed");
xfa.event.change="";
}
or even try this:
if (xfa.event.change==" "){
xfa.event.change="_";
}
Kyle
Views
Replies
Total Likes
That works great! Thanks so much Kyle.
-Don
Views
Replies
Total Likes
This script allowed each number (e.g. 0,1, 2..) and each character (e.g. a,b, c, A, B, ..) and each special character (e.g. ; : _ § % &).
Not allowed is a space.
if(xfa.event.newText.match(/[/\s]/))
{
xfa.event.change = "";
}
I hope it was also helpull for you,
Mandy
Yes, thank you. The script Kyle provided also allows special characters ( _ , – , (), etc... but not a space.
Views
Replies
Total Likes
You are right. I saw and tried only the second version and thought you need something without _
Kind regards Mandy
Views
Replies
Total Likes
Thanks Mandy. I appreciated your input and reply!
Thanks,
-Don
Views
Replies
Total Likes
Hi Don,
You're welcome.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies