Quantcast
Channel: Adobe Community : Popular Discussions - JavaScript
Viewing all articles
Browse latest Browse all 12130

Validate numbers and some characters in a form field.

$
0
0

Dear all

I am creating a form and in it, there are fields for email and phone number.

I found http://forums.adobe.com/thread/857974

to be really useful in helping me validate my email field.

 

Then I tried to tweak that for the phone number field which I need to only allow the characters 1234567890+()

As you can see, its just numbers and +(). How to I restrict the field to only accept those characters?

 

I tried this but it failed:

 

// Custom Validate script for text field

(function () {

 

          var val = String(event.target.value);

 

          // Do nothing if the field is blank

          if (!val) return;

 

          // If the value is not a valid telephone number...

          if (!val.match(/\+?[0-9\(\)]*/)) {

 

                    // ...let the user know the value is not a valid telephone number...

                    app.alert("Please enter a telephone number, eg +012(3)123123123", 3);

 

                    // ...and set the focus back to this field

                    event.target.setFocus();

}

})();

 

But it does not work. Sigh.

I have 0 background in computer language (I'm a biologist, and this is a form for doctors to fill up patient data), and would appreciate some help in getting the phone field validation to work.

 

Thanks!


Viewing all articles
Browse latest Browse all 12130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>