1 Reply Latest reply on Sep 24, 2010 10:32 AM by George_Johnson

    Limiting a Text Box to certain Charachters

    Elondon883 Level 1

      I would like to run a custom validation script for a text box. I need the text box to only allow letters a-z, numbers 0-9, and the - charachter.

       

      If someone enters any other charachter, such as a / or &, I would like an error message to appear once the click off the text box saying that this text box only allows characters a-z, 0-9 and -.

        • 1. Re: Limiting a Text Box to certain Charachters
          George_Johnson MVP & Adobe Community Professional

          You can use the following as a custom Validate script for a text field:

           

          (function () {

           

              // define regular expression
              var re = /[^a-z0-9\-]/;

           

              if (re.test(event.value)) {

           

                  app.alert("Your message goes here.");

           

                 // Optionally, reject value
                 event.rc = false;
              }

          })();

           

           

          I often find it better to simply reject invalid characters using a Keystroke script and not bother with annoying pop-ups messages.