Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Custom validation script - coding help needed
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Custom validation script - coding help needed

 Post Reply Post Reply
Author
PricesAreDan View Drop Down
New Member
New Member


Joined: 07 Aug 2013
Location: Australia
Points: 2
Post Options Post Options   Quote PricesAreDan Quote  Post ReplyReply Direct Link To This Post Topic: Custom validation script - coding help needed
    Posted: 08 Aug 2013 at 12:21am
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 committed
if (event.willCommit == false)
{
// test keystroke against the RegExp
if(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 blank
if (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?


Edited by PricesAreDan - 08 Aug 2013 at 12:23am
Back to Top
Sponsored Links


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.