473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how do i limit user choice to three options?

I have a field that allows entries of 1 to 100, or the value "r" or the value "i" or the value "na"

My script looks like this, but it continues to allow duplicate entries of the "i" and the "r" when the
"i" is entered on the change* event. What is missing?

if (xfa.event.change!="" && !xfa.event.newText.match(/^[0-9]+(\+|-)?$|^(na?)?$|^(r)?$|^(i)/)) {
xfa.event.change ="";
xfa.host.beep("3");
}
Oct 14 '14 #1

✓ answered by Rabbit

If it's testing fine then it's correct. But it can be cleaned up a little.
Expand|Select|Wrap|Line Numbers
  1. /^([1-9][0-9]?|100|n|r|i)$/

26 1493
Rabbit
12,516 Expert Mod 8TB
I don't know what it is you're trying to do. Your regex makes no sense.
Oct 14 '14 #2
I'm working in livecycle designer es4. I want to limit the entry to the following options: any numerals 1-100; and then three entries only: the value "na", the value "r" or the value "i".
This is on the change event. Everything works except that the "i" value also accepts "ir"

This is the script that works with the exception as noted above:

if (xfa.event.change!="" && !xfa.event.newText.match(/^[0-9]+?$|^(na?)?$|^(r)?$|^(i)?$/)) {
xfa.event.change ="";
xfa.host.messageBox("Oops, incorrect entry, or caps lock are on. Thank you.");
}
Oct 14 '14 #3
Rabbit
12,516 Expert Mod 8TB
That looks convoluted, try this: /^[0-9]+(na|r|i)$/
Oct 14 '14 #4
When i change the script as per above, I can get the numerals, but no other entries. Only numerals are to be allowed, OR any of the three options, but not both.
Oct 14 '14 #5
Rabbit
12,516 Expert Mod 8TB
Works fine for me in a regex tester. Please post your newly updated code.
Oct 14 '14 #6
Here is the revised script I am trying on your suggestion:

On change*
// Test input in real time. Only allow approved grades, r, i, na
if (xfa.event.change!="" && !xfa.event.newText.match (/^[0-9]+(na|r|i)$/)) {
xfa.event.change ="";
xfa.host.messageBox("Oops, incorrect entry, or caps lock are on. Thank you.");
}
Oct 14 '14 #7
Rabbit
12,516 Expert Mod 8TB
Don't know what could be wrong. I tested it in a regex tester and it matched: "1na", "949r", "838838i". But did not match "1", "na", "iiiii".

One thing you can test is to output the value to make sure it's testing the correct input string.
Oct 14 '14 #8
Thanks for continuing to stick with me! Output values should be restricted to:
either a number
OR
the value of "r"
OR
the value of "i"
OR
the value of "na"

So no combined values, just the very specific options as above. Do you mind having another look?
Oct 14 '14 #9
Rabbit
12,516 Expert Mod 8TB
That's not what you said in post #3... But no matter, it's a simple fix, include the digits in the parentheses and add a pipe character.
Oct 15 '14 #10
Sorry about that ... would you mind sending along the code as you suggested? I know I'm missing something here...
Oct 15 '14 #11
Rabbit
12,516 Expert Mod 8TB
Fairly simple change to my original code
/^([0-9]+|na|r|i)$/
Oct 15 '14 #12
Thank you ... I've tried the code and I can make entries for any number values that are three digits, or I can enter the value "r" or I can enter the value "i".

These are all good, but now I can't successfully enter the value "na". Do you have a suggestion for how i can do this successfully, and also without running into the problem where either the "n" or "a" values can be entered separately without throwing an error?
Oct 15 '14 #13
Rabbit
12,516 Expert Mod 8TB
You should be aware that it doesn't limit to 3 digits. You can have any number of digits, if you need only 3, then you need to put that into the expression.

The reason you can't enter na is because you are calling the code on change. That means as soon as you enter n it calls the code and it throws an error. You need to use a different event. Like an after update event or a lost focus event. One that only fires after they have finished entering data in that field.

You shouldn't be able to have an "n" or "a" by itself as a valid value. Those values aren't among your list of acceptable values. If you are changing what is acceptable, then you can just add them to the expression like any of the other values, within the parenthses separated from the other values with a pipe character.
Oct 15 '14 #14
The field length is limited to a maximum of three characters, so that isn't a problem. But I see what you mean with entering n on change using your script. Could you resend your script to show that the digits are limited to only the values of 0 to 100 (like grades on a report card?) I'll keep at it ...
Oct 15 '14 #15
Rabbit
12,516 Expert Mod 8TB
To limit it to 0-100, change it from any number of digits to any 2 digit number or 100.
Oct 15 '14 #16
I have decided to work with this approach for what I need to accomplish:

On change*
// Test input in real time. Only allow approved grades, r, i, n with the code on exit replacing n with na
if (xfa.event.change!="" && !xfa.event.newText.match(/^[0-9]+?$|^(^n?)?$|^(r)?$|^(i)?$/)) {
xfa.event.change ="";
xfa.host.messageBox("Oops, incorrect entry, Please correct your input. Thank you.");
}

Then on exit*
this.rawValue=this.rawValue.replace(/n/g,"NA")
this.rawValue=this.rawValue.toUpperCase()

The user is restricted to entering the three options "r", "i", or "n" where "n" is replaced by "na" on exit and all the values are also uppercased. The digits are limited to 3 by virtue of the field length limit.
I have no idea how to limit the number entries from 001 to 100, so that is unfortunate. I'm still open to some help on this! Thanks for all the input...
Oct 15 '14 #17
Rabbit
12,516 Expert Mod 8TB
001-100? Or 1-100? They're different. If the former, limit the first digit to 0 and 1, and the next 2 digits to any number. If the latter, use the method I described in post #16
Oct 15 '14 #18
OK, good idea! But where do I find post #16. I looked, I promise!
Oct 15 '14 #19
Rabbit
12,516 Expert Mod 8TB
This post is 20, look up 4 posts.
Oct 15 '14 #20
How does this look? (I'm still getting an error when i input three digits like "560:...)
On change*
//Test input in real time. Only allow approved grades, r, i, na
if (xfa.this.change!="" && !xfa.event.newText.match(/^([1-9]{1,2}[0]?|100+|n|r|i)$/)) {
xfa.event.change ="";
xfa.host.messageBox("Incorrect entry.. also, n outputs NA. Thanks!");
}

On exit*
this.rawValue=this.rawValue.replace(/n/g,"NA")
this.rawValue=this.rawValue.toUpperCase()
Oct 16 '14 #21
Hello Rabbit,
I've amended the regex for the number entry:

//Test input in real time. Only allow approved grades, r, i, na
if (xfa.this.change!="" && !xfa.event.newText.match(/^[1-9][0-9]?$|^100|^(n?)?$|^(r)?$|^(i)?$/)){
xfa.event.change ="";
xfa.host.messageBox("Incorrect entry.. also, n outputs NA. Thanks!");
}

On exit*
this.rawValue=this.rawValue.replace(/n/g,"NA")
this.rawValue=this.rawValue.toUpperCase()

I think this time I've got it...
Oct 16 '14 #22
Rabbit
12,516 Expert Mod 8TB
Your first attempt is closer, your second one has a bunch of extra stuff for some reason, even on stuff that was working fine before.

Take the first attempt and fix that one. For example, your piece with the 100, you have a plus sign in there for some reason, that tells the expression to match as many zeroes as possible.

And for the piece that defines any two digit number, for some reason you tell it can have an optional zero at the end.
Oct 16 '14 #23
You're right: messy code! How about this? It tests fine inside Livecycle ...

On change*

if (xfa.this.change!="" && !xfa.event.newText.match(/^[1-9][0-9]?$|^100|^(n|r|i)$/)){
xfa.event.change ="";
xfa.host.messageBox("Incorrect entry.. also, n outputs NA. Thanks!");
}

On exit*
this.rawValue=this.rawValue.replace(/n/g,"NA")
this.rawValue=this.rawValue.toUpperCase()
Oct 16 '14 #24
Rabbit
12,516 Expert Mod 8TB
If it's testing fine then it's correct. But it can be cleaned up a little.
Expand|Select|Wrap|Line Numbers
  1. /^([1-9][0-9]?|100|n|r|i)$/
Oct 16 '14 #25
Thanks so much for sticking with me on this. Your code got rid of the some of the extraneous stuff, and works properly! Thanks again for the help.
Oct 16 '14 #26
Rabbit
12,516 Expert Mod 8TB
No problem, good luck with the rest of your project.
Oct 16 '14 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Peter | last post by:
How can i limit the number of users on my .ASP page, i want only one user to be using the page at a time, The query i have on my page is big and takes a lot of my system resources. John
0
by: Noitanon | last post by:
Hello, Looking for people to allow me hints, links, book chapter references on making a deployment projekt in my .net (C#) windows forms Solution that results in an installation giving user...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
1
by: cw | last post by:
Hi all, Is anyone have an idea that limit message length input by user into textbox. I'hv tried the maxlength property by setting it to 150, but it seems like not working.., regards
0
by: Elie Nacache | last post by:
Hi all, I've a Java application using postgresql-7.4.3. I'd like to not allow same user open 2 concurrent database sessions, because multiple sessions one user always cause trouble. how to do...
4
by: Randy Smith | last post by:
Hi, I would like to limit my user selection to only one row in the GridView at a time. Is there any way to set this? TIA, Randy
1
by: helraizer1 | last post by:
Hi folks, In my script I have this code: <?php unset($errors); include ("linesfile.php5");
6
by: jasone | last post by:
Hi all! im developing a system where a user can select what flower goes into their bouquet, and ive become a little bit stuck... heres what ive done to date: currently ive got a page displaying...
2
by: Mihai Popescu | last post by:
Is there a way to select lets say max selected options from a <select> tag... for example I have a select with 150 options... but I want to select maximum 30... I've tried with js onclick and...
4
by: game2d | last post by:
when user press can key than the code below gets the key user just pressed. the problem is that i want to only limit user to press alphabet and numbers. so i want to disable weird char ex left,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.