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

Custom validation script - coding help needed

$
0
0

Hi guys,

 

I have a conundrum with a form I'm trying to scrap together a custom validation script for.

Coding is not my strength but I can copy & paste and get the idea but for this exercise it seems the Javascript is beyond me.

 

I have a field in a form which a user needs to enter a 'valid' Noosh code.

The Noosh code consists of 5 numbers, a letter then two numbers.

  E.G: 56413P01 or 34265P05 or 84172P13

The field doesn't need to check against codes in a list, it simply needs to reduce input error to do with an extra number or dropping a number etc. Basically it needs to pertain to the above format before submission.

 

I've been trying to muck around with this code which I feel is on the right track (pulled from another source):

 

// Custom Keystroke script:// RegExp for keystrokes
var re = /^\d{0,3}(\-)?\d{0,3}(\-)?\d{0,4}$/ // run only if field not committedif (event.willCommit == false){// test keystroke against the RegExpif(re.test(event.change) == false){// we have an invalid keystroke
app.beep();// force field to clear
event.rc = false;}} // Custom Format script // RegExp input (999-999-9999) for format
var re = /^(\d{3})[-](\d{3})[-](\d{4})$/ if(re.test(event.value) == true){// drop "-" and add "."
event.value = RegExp.$1 + "." + RegExp.$2 + "." + RegExp.$3;} // Custom Validation script:// only run when field not blankif (event.value != ""){// RegExp for validation 999-999-9999
var re = /^(\d{3})([-])(\d{3})([-])(\d{4})$/ if(re.test(event.value) == false){
app.alert("Enter 10-digit phone number beginning with area code (e.g., 916-456-8910) - It will be converted to the format 916.456.8910 as that is how it will appear on the business card");
event.rc = false;}}

 

 

In actual fact the script doesn't seem to work for the format it's alerting to but in my naive opinion it seems to have the right elements, keystroke something, validation check and an alert.

 

My problem is massaging this to make it fit to my requirements, besides the fact that it didn't work I couldn't decode the character expressions ( E.G: var re = /^(\d{3})([-])(\d{3})([-])(\d{4})$/)

Am I even on the right track?

Can someone help me format it to suit my needs?


Viewing all articles
Browse latest Browse all 12130

Trending Articles



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