Limit the amount of characters of a text field based on first digit

Hello and thanks in advance for your help!
I would like to limit the amount of characters of the text field based on the first digit of the number (the text field is only limited to a number format...no decimals, no commas).
For example, if the number begins with a 3, I would like to limit the text field to allow only ten characters. I have three scenarios but if I could get started with some code and what is the best place to add it (keystroke or validation?) I can take it from there. Thanks again for your help!!

I've written this code for you that does that. Use it as the field's custom Keystroke code:
// Validate that only digits are entered
if (event.change) {
    event.rc = /^\d+$/.test(event.change);
// Validate string length if it starts with 3
if (/^3/.test(AFMergeChange(event))) {
    event.rc = AFMergeChange(event).length <= 10;
    if (!event.rc) app.alert("If the number starts with \"3\" it may not be longer than 10 digits.",1); // optional error message
You can duplicate the second part of it for additional conditions, but keep in mind that this code won't even let you remove the first character in the field if the result is an invalid one.
For example, if you enter "234567890123456" then you can't remove the "2" at the start because that would result in an invalid number. You can remove any of the other digits, though, and when it's 10 digits or less then you could remove the starting "2" as well.

Similar Messages

  • How do you limit the amount of digits in a text field?

    If a user was to input 9 digits into a text field. How do you make it so that an error message would appear if the user inputs more than 9 digits

    That code will set the TextFields length to 9 standard charecters (might not be 9 though) To limit the number of charecters and throw an error message I would use a listener on the textField. Perhaps a keyListener that keeps track of the number of charecters. ( swing has document listeners which are really nice )

  • How can I do field validation on the last two characters of a text field?

    I have a text field. The user is required to enter the last two characters as numbers. I want to apply validation on this field. How can i achieve the same?
    EX: If the user enter ABCDE, an error messgae stating the last two digit should be numeric.
    I tried using the below in the field validation which did not work.
    (0+Right([<ExternalSystemId>],2)) > 0 AND (0+Right([<ExternalSystemId>],2)) < 99.
    Any ideas would help?

    Try this-
    FindOneOf(Right([<Field1>],"2"),"abcdefghijklmnopqrstuvwxyz")=0
    rgds,
    Amit

  • I need a query that returns the average amount of characters for a text colum in MS SQL.

    I need a query that returns the average amount of characters
    for a text colum in MS SQL.
    Could someone show me how?

    Sorted, i need the
    DATALENGTH
    function

  • Limit the number of characters in Text Components

    I'm trying to limit the number of characters in text components. So I use the follow KeyListener:
    private class KeyHandler extends KeyAdapter{
    String oldText;
    private KeyHandler(){ }
    public void keyTyped(KeyEvent ev){
    String newText = textField.getText();
    System.out.println("Old text: " + this.oldText); //debug
    System.out.println("New text: " + newText); //debug
    if(newText.length() < limit){
    this.oldText = newText + ev.getKeyChar();
    }else{
    textField.setText(this.oldText);
    if(textField.getCaretPosition() + 1 > limit)
    textField.setCaretPosition(limit - 1);
    But the problem is that after that, the last key is typed in the component and the last key always appear.
    �Does anyone know the way for consume the key presses?
    Thank you

    (Belongs in the Swing forum.)
    The callback method keyTyped comes after keyPressed and keyReleased.
    The event.consume() should consume the event.
    Consider cut/copy/paste.
    Maybe a addPropertyChangeListener would be better?

  • To limit number of characters in a text field...

    I did a little research. My goal is to limit the number of characters in the textfield by 50.
    If the results of my research are correct, I have to create a JFormattedTextField, then use a MaskFormatter with a mask of 50 asteriks. Is that correct? Any other suggestions?
    Thanks in advance.

    I've got a problem using a JFormattedTextField.
    Each time the the text field gains focus, the caret does no move to the end of the text. It appears at the start of it. plus, any text i typed will overwrite the character already typed in, as if you've pressed the INSERT button during typing in a text editor.
    What caused that and how do I resolve it?
    Thanks a lot for the help ;)

  • How to limit the number of characters entered in a JTextfield???

    Hello there,
    I have created a Text box using swing component JTextField and I want to limit the number of characters entered to 8 characters..how do i proceed with that?
    Thanks in advance!
    Joe

    Ty out this
    import com.sun.java.swing.text.*;
    //import javax.swing.text.*;
    public class JTextFieldLimit extends PlainDocument {
    private int limit;
    // optional uppercase conversion
    private boolean toUppercase = false;
    JTextFieldLimit(int limit) {
    super();
    this.limit = limit;
    JTextFieldLimit(int limit, boolean upper) {
    super();
    this.limit = limit;
    toUppercase = upper;
    public void insertString
    (int offset, String str, AttributeSet attr)
    throws BadLocationException {
    if (str == null) return;
    if ((getLength() + str.length()) <= limit) {
    if (toUppercase) str = str.toUpperCase();
    super.insertString(offset, str, attr);
    import java.awt.*;
    import com.sun.java.swing.*;
    //import javax.swing.*;
    public class tswing extends JApplet{
    JTextField textfield1;
    JLabel label1;
    public void init() {
    getContentPane().setLayout(new FlowLayout());
    label1 = new JLabel("max 10 chars");
    textfield1 = new JTextField(15);
    getContentPane().add(label1);
    getContentPane().add(textfield1);
    textfield1.setDocument
    (new JTextFieldLimit(10));

  • How to limit the number of characters a label displays?

    Can someone please tell me how I can limit the number of characters a label displays from the text property?

    Ok. What I am trying to do is display a number with the format
    x.yy
    I need the display to show all characters all the time.  For example let me show you what I currently get and what I require.
    Current     Require
    0               0.00
    0.1            0.10
    etc
    To me its like the label is truncating the number appropriately and I dont want it to do that.  I need a fixed 4 character format.
    Hope this clears it up.

  • How to limit the amount of disk space Time Machine will use?

    On Yosemite, how do you limit the amount of disk space Time Machine will use?
    I'm using a Seagate Goflex Home 2tb drive connected to my router as a Time Machine backup drive.  I use this for three things 1)Time Machine 2) an occasional backup of  windows document subdirectory  3) backup of music and photos for long term storage.   Doing something like re-partioning the drive is not an option.  I'll just go buy another drive for time machine's sole use. In addition, using software from Seagate is not an option.  I don't want to use their software for different reasons (mainly the GoFlex home is really designed as a "media server"  which I don't use.  I, of course, use iTunes. ) On the Mac, I'm only using about 250GB total but time machine is rapidly using up space.
    Apparently using a terminal command like below, used to work,  but no longer works under Yosemite.
    For a limit of 100gb the number below would be 100 x 1024
    sudo defaults write /Library/Preferences/com.apple.TimeMachine MaxSize 102400
    To remove the limit, use the following command:
    sudo defaults delete /Library/Preferences/com.apple.TimeMachine MaxSize
    Now, I'm not too familiar with terminal and I'm not about ready to issue a command without knowing exactly what it is going to do.
    Is there an easier "switch" someplace or an app that does this?
    If I don't limit the size, at some point there will not be any space left for windows backups and additional photo and music files.

    Hmm- added "sudo" and there was no error reported:
    sudo defaults write /Library/Preferences/com.apple.TimeMachine MaxSize xxxxxx
    I guess we'll see.

  • Limit the amount of tasks that a user can claim

    I have a custom worklist and I need to develop a requirement for not allowing the users to claim more than one task at a time. Does the Worklist API have something to limit the amount of tasks that a user can claim at a time?.
    Thanks in advance.
    Neuquino

    Apparently the Family Base add-on (https://my.verizonwireless.com/vzw/nos/safeguards/SafeguardProductDetails.action?productName=familybase) from Verizon will allow you to set limits on how much data a particular device can consume.  I think it is free for the first 3 months (not sure) after that it will cost $5 per month.  I have heard rumors though that it does not work well with iPhones???

  • How can I limit the amount of space on a Time Capsule used by Time Machine?

    I know that you cannot partition a Time Capsule drive.  However, I was wondering about other options for limiting the amount of space used by Time Machine so that I can use the rest of the space for other purposes.
    I heard something about creating a disk image on the Time Capsule to limit the amount of space used by Time Machine.  If I create a disk image, would TM just use all the space that's not part of the disk image?  How do I access the disk image part?  Can I manually drag and drop files to it from my Mac like any other external drive?  Could I set up the disk image part to work with a Windows computer?
    I've also heard things about modifying sparsebundles which I don't know anything about.  How does this work?  What happens to the space that is not part of the TM sparsebundle?  How do I access it?  Can I manually drag and drop files to it from my Mac like any other external drive?  Could I set up the extra space to work with a Windows computer?

    Some other things to make note of:
    Some disk image formats have a maximum size and only use that size after they have had to expand to actually hold that much data. Make sure you are not using this type of image so you can guarantee the space is reserved. Sparse bundles are like this. I haven't read up on the sparse bundle trick, but I assume it's something to do with setting a maximum size for it.
    When you open up the Time Capsule disk, you will first be looking at the normal storage space. When you create an image, there will be a file you click on that mounts another drive that uses space on the Time Capsule. This shows up as just one file unless you open it to see it's contents.

  • Auto claim a Task in the Worklist and limit the amount of assings per user

    Hi, I have two questions:
    1) Is there a way to implement "auto claim" in the worklist? I need to assign the task to the logged user as soon as the task is opened by the user.
    2) Is there a way to limit the amount of tasks that the user claims? I need to avoid the situation of a user claiming more than one task. In other words, I need that "If a user claims a task, he MUST release or action it before claiming another task"
    Thanks in advance,
    Edited by: Neuquino2 on Apr 30, 2010 1:03 PM
    I'm working with 11g

    Ok, I understand your use case for question 1. I actually have this same problem I have been trying to solve for a couple of weeks and haven't found a solution. My use case is slightly different. I have to assign to a group, but in some cases, I know which user in the group the task should be assigned to. However, the requirement is that I assign to the group. So I am trying to figure out how to use the routeTask method of the task service to route the task to the user after the task has already been created and assigned to the group. Not sure yet if that works. I have an SR open with Oracle Support. In your case, it sounds like you want the first member of the assigneeGroup who looks at the task to become the acquiredBy user. I would assume you would need to use routeTask in the Workflow API (in my case, I am using routeTask from BPEL).
    On the second question, I doubt that you will find any out-of-box mechanism to do this. There are the three workload balancing rules built into workflow API and available in the worklist application - round robin, least busy, and most productive. But none of those will fit your requirement. However, supposedly you should be able to create your own algorithm. I don't know how to do this, but there should be some place in the documentation that tells you how to do it.

  • How do I limit the amount of emails in my inbox

    We have a mail server at our business, I receive my mail on my PC, laptop,iPad and iPhone. The iPhone and iPad fetch my mail and as soon as I read my mail on my iPhone or iPad it loads old mail from the server. This did not happen before our last update from Apple.
    This means I pay at least 3 time to download my mail.
    Is it possible to limit the amount of mail and only receive the heading and download the rest should you need to?

    This is no longer an option.
    Feel free to let Apple know about it by sending them feedback:  www.apple.com/feedback

  • HT204264 How do I limit the amount of space used by photos on my phone - now that I turned iCloud on it is taking over my phone

    How do I limit the amount of space used by photos on my phone - now that I turned iCloud on it is taking over my phone

    Hello Maahk,
    Welcome to the Apple Support Communities!
    I understand that you would like to optimize your Photos storage. If you are using iCloud Photo Library on your iPhone, please read over the information in the attached article. 
    iCloud Photo Library FAQ - Apple Support
    Can I use iCloud Photo Library to save space on my device?
    iCloud Photo Library automatically keeps all your photos and videos in the original, high-resolution version. Follow these steps to choose how you store your photos and videos on your device:
    In iOS, tap Settings > iCloud > Photos or Settings > Photos & Camera, then select a storage setting.
    In OS X, click Photos > Preferences > iCloud, then select a storage setting. 
    If you turn on Optimize [device] Storage, iCloud Photo Library will automatically manage the size of your library on your device, so you can make the most of your device's storage and access more photos than ever. All of your original, full-resolution photos and videos are stored in iCloud while device-size versions are kept on your device. You can download the original photos and videos over Wi-Fi or cellular when you need them. 
    If you turn on Download Originals, iCloud Photo Library will keep your original, full-resolution photos and videos in iCloud and on your device. Download Originals is the default setting for iOS devices with the free 5 GB storage plan and for all Mac devices.
    Have a great day,
    Joe

  • Can you limit the amount of data accessed per user on an AirPort Extreme?

    Can you limit the amount of data accessed per user on an AirPort Extreme?

    Your question was whether the AirPort Extreme is able to establish data limits per user.
    If you add another router that has this type of capability or install software on another router, then you will be able to establish data limits for each user. The AirPort Extreme will have no control over this.

Maybe you are looking for