Restrict the input string length

Hi, how do I restrict the input string length in a JTextField. Suppose if I want my text field to accept only 4 characters, the fifth character I try to enter shouldn't be accepted in the field.
Thanks,
Kalyan.

This is for 6 characters limit
//create a JTextField that is six characters long
JTextField textField = new JTextField(new FixedNumericDocument(5,true),"", 6);
Here boolean true means only numeric. set to false to take in alphanumeric.
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
public class FixedNumericDocument extends PlainDocument {
private int maxLength = 9999;
private boolean numericOnly;
public FixedNumericDocument(int maxLength, boolean numericOnly) {
super();
this.maxLength = maxLength;
this.numericOnly = numericOnly;
//this is where we'll control all input to our document.
//If the text that is being entered passes our criteria, then we'll just call
//super.insertString(...)
public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
if (getLength() + str.length() > maxLength) {
return;
else {
try {
if (numericOnly) {
Integer.parseInt(str);
//if we get here then str contains only numbers
//so that it can be inserted
super.insertString(offset, str, attr);
catch(NumberFormatException exp) {
return;
return;

Similar Messages

  • How to pick up the last value of the input string

    Hi there,
    I have a requirement in which I have to pick up the last value of the input string.
    I don't know the field length, it could be 10 line, it could be 4 line and it could be even 1 line.
    Another problem is that the field contains all the alphanumeric values so the sort function is not working.
    I believe I need to write a UDF but not sure exact what and how.
    Can some body please help me solving this issue.
    Input.
    1.Abc
    2.abc123atxx.com
    3.(980)771-2341
    4.
    5.518VR50V58AD10DSAYBDSAFDSIEGHA:1
    In that case I only need to pickup the last value i.e. 518VR50V58AD10DSAYBDSAFDSIEGHA:1
    Output
    518VR50V58AD10DSAYBDSAFDSIEGHA:1
    Note:
    1. Length is unknown
    2. Alphanumeric data
    Thanks,

    Hi karthick Lakkar,
    Thanks for your quick response but unfortunately I am getting mapping exception.
    What I did is create a UDF with 2 input
    INPUT
    a string
    b string
    and then this code
    int Length=Integer.parseInt(a);
    int requiredLength=Integer.parseInt(b);
    if(Length<=requiredLength)
    return(a);
    else
    return a.substring((Length-requiredLength),Length);
    I am wondering about the input as well.
    At present I am doing
    KTEXT + KTEXT --- UDF
    + does represent concat, means same input will go to the UDF
    This is the error which I am getting
    Exception:[java.lang.NumberFormatException: For input string: "Kevin Farrar"] in class com.sap.xi.tf._MM_XXXXXXXXXXXXXX_ method calculate[Kevin Farrar, Kevin Farrar, com.sap.aii.mappingtool.tf7.rt.Context@6dbf19db]

  • How do I program Instrument I/O Assistant to read a variable in the input string?

    How do I program the Instrument I/O Assistant to read a variable in the input string? I can manually type in the string using the Instrument I/O Assistant using the "Write" or "Query" tools but I do not know how to send a variable input to the Instrument I/O Assistant so that variable can be used inside the "Write" string. For example, I have a power supply whose current I want to set to X Amps. I can type the command "PC10" to program the current to 10 Amps, however I want to be able to program it at any arbitrary current. How do I feed the value X into the code for this purpose?

    You can't. The assistant was designed to be a quick and dirty way to do some basic communication with an instrument. You can turn it into a VI (right click and select Open Front Panel) and modify it so that your write string is an input to the VI or use it as a template and create your own code with VISA Read and Write primatives.

  • Transaction F110 - Possible to restrict the input of Identification-field?

    Hello all,
    is it possible to restrict the input of the "Identification"-field in transaction F110 (Automatic Payment Transactions: Status)?
    e.g.: User X with company code XX is only allowed to enter XX01 in the identification field.
            User Y with company code YY is only allowed to enter YY01...
    Is that possible?
    Thanks in advance for any reply!
    Steffen
    Message was edited by:
            Steffen Poetsch

    Hi
    You can control the "identification" with the help of the BASIS guy.
    They will define the authorization object to field level.
    Create seperate roles for that and assign accordingly
    VVR

  • How to know the total string length of a range of cell in excel sheets

    Hi,
           I am working on Excel automation. I want to read data of collection of cells from excel for that i need to know the total string length in one shot.
    Can anyone suggest me the answer for this

    Still not sure about your requirements, but how about this
    SQL> CREATE OR REPLACE FUNCTION get_max_length(p_table in varchar2, p_col in varchar2) return pls_integer
      2  is
      3    v_cnt pls_integer;
      4  begin
      5    execute immediate 'select max(length('||p_col||')) from '||p_table into v_cnt;
      6    return v_cnt;
      7  end get_max_length;
      8  /
    Function created.
    SQL>
    SQL> SELECT COLUMN_NAME,
      2         DATA_LENGTH,
      3         get_max_length(TABLE_NAME, COLUMN_NAME) max_length
      4  FROM USER_TAB_COLUMNS
      5  WHERE TABLE_NAME='EMP'
      6  AND DATA_TYPE like '%CHAR%'
      7  ;
    COLUMN_NAME                    DATA_LENGTH MAX_LENGTH
    ENAME                                   10          6
    JOB                                      9          9
    SQL>

  • HOW to Restrict the input Help for 0MATERIAL in the BPS Layout

    Hi,
    I have requirement to Restrict the input Help for 0MATERIAL  in the BPS Layout.
    For Example if the Planning Package is Restricted to SALES ORGANISATION ( 3000 )  then the system shuold  check the 0MAT_SALES  where SALES ORGANISATION IS "3000" )AND PASS THE Material Numbers to the 0material list.
    I have Copied the standard Funtcion group  "UPF_VARIABLE_USER_EXIT"  to Z fucttion and have attached to Z Variabe as User Exit .
    this Variable is  Attached to 0material in the Planning Pakage. So tha now the 0MATERIAL is restricted to the variable which is having the User Exit.
    But how to acces the Values of Planning Package for which the Layout is bein Executed from this Z User Exit ???
    I Know how to restrict the input help, but my only problem is that how to get the values of Planning package through this User Exit.
    Please suggest if it is possible.
    Regards,
    Nilesh Labde

    Hi Nilesh,
    As I understand from your question,you know how to restrict but the issue is to know the value in the package with which you need to restrict.
    There are two tables which can help you finding the value used in package for sales organisation:
    1. UPC_PACKAGE
    2. UPC_OPTIOS
    How to use ?
    From UPC Package you will get one GUID, Hit the second table UPC_OPTIOS with this GUID.
    In field "FIELDNAME" enter the name of the characteristic whose value is req (sales organisation in your case)
    Hope this helps you
    Mann

  • How to increase the input filed length in a sap standard transaction

    Hi All,
    Below is my user's requirement.
    Tcode->FS00-->f4 help for GL account number --> in this pop-up go to the tab G/L Account description in company code
    Here the input field G/L Long text allows 25 chars as input where as user want it to increase till 50 chars.
    Actually this input field G/L Long text  is refering the sap standard database view GL_ACCT_CC_TEXT (Field: MCODF of length 25)
    Is it possible to increase to search to 50 chars, if so how to do the same.
    --Rose.

    Well documented, please have a look:
    http://help.sap.com/saphelp_nw04s/helpdata/en/1f/29ef5777df11d2959800a0c929b3c3/frameset.htm
    The collective search help to be extended is SAKO.
    Thomas

  • How to convert special characters like #, &, etc occuring in the input string

    Hi,
              I am using method 'Get' to submit a form . When ever there is any
              special character like '#' in my input For example "033#Test", nothing
              gets posted beyond 033.
              Can any one please let me know how do I overcome this problem.
              Thanks in advance.
              Regards,
              Moin
              

    Moinuddin:
              It seems possible your browser may be confused by the fact that 033 is
              the octal representation for an ESCape character (Hex 1B). Try dropping
              the leading zero. In addition, it is usually better to represent special
              characters like the hash mark "#" using HTML character entities instead
              of literals, i.e. &#35; = hash mark
              Regards,
              Jim Brown
              Moinuddin Ahmed wrote:
              >
              > Hi,
              > I am using method 'Get' to submit a form . When ever there is any
              > special character like '#' in my input For example "033#Test", nothing
              > gets posted beyond 033.
              >
              > Can any one please let me know how do I overcome this problem.
              >
              > Thanks in advance.
              > Regards,
              > Moin
              Jim Brown
              Developer Relations Engineer
              BEA Support
              

  • Restrict the input in condition type

    Hello Friends,
    In my PO there are six condition types used for freight calculation my requirement is when user enter value in any condition type thn all the remaining 5 condition types should not allow any entry(it should become grey).
    pls let me knw how we can achieve this?
    Sunny

    Hi
    Try using the Condition Exclusion Groups
    SPRO-> IMG-> MM-> Purchasing-> Conditions-> Define Price Determination Process-> Define Condition Exclusion
    If several condition records are valid in the price determination process, you must define rules stipulating which conditions are selected and which are disregarded. To do this, use the condition exclusion mechanism.
    The exclusion of condition records is controlled via exclusion groups. An exclusion group is a list of condition types that are compared with each other during the price determination process. The result may be the exclusion of a whole group of conditions or the exclusion of individual conditions within a group.
    The result of the price determination process can thus be influenced with regard to a desired criterion (for example, the lowest price) by the exclusion of certain condition types, whereas others are taken into account in this process.
    Example
    You can define a condition exclusion process that determines the most favorable price and excludes less favorable but fundamentally possible pricing results. The lowest price then overrides the condition type priorities that would have been dictated by the access sequence.
    In the calculation schema you define the procedure by which selection within or between the condition exclusion groups takes place. The following possibilities are available:
    Selection of the most favorable condition type within a condition exclusion group.
    Selection of the most favorable condition record of a condition type if more valid condition records exist (for example, selection from different condition records of condition type PR00)
    Selection of the most favorable of two condition exclusion groups (in this case, all condition types of the two groups are cumulated and the totals compared with each other)
    The tables for the exclusion of conditions are supplied empty. You must therefore work through the following points if you wish to use the condition exclusion facility:
    Define condition exclusion groups
    Assign condition types to condition exclusion groups
    Enter condition exclusion groups in the calculation schema and define a procedure for the determination of the condition types to be excluded.
    Activities
    1. Create a condition exclusion group by entering an alphanumeric key that is max. four characters long, together with a description.
    2. Assign the condition types to a condition exclusion group. A condition exclusion group can contain any number of condition types.
    3. Enter the condition exclusion group in the calculation schema that you will be using for price (or cost) determination purposes.
    4. In the process, note the sequence (consecutive numbers) in which the exclusion groups are to be processed.
    Using this yuou can achive your requiremnt .
    Thanks & Regards
    Kishore

  • How to restrict the length of the input?

    Hi all, could any one tell me how to restrict the length of the input string? My SOA Suite is 10.1.3.1
    I tried the following; getting an error.
    <element name="RestrictLengthProcessRequest">
    <simpleType name="SSN">
    <restriction base="string">
    <length value="10"/>
    </restriction>
    </simpleType>
    where RestrictLengthProcessRequest is the message name of the corresponding .wsdl and SSN is the input whose length is to be restricted.
    The error is : 'Attribute name not defined on element simpleType'
    Thanks in advance.
    Edited by: user11275112 on Aug 27, 2009 11:44 PM

    Hi swathi,
    For this you have to create a simple data type. No need of writing a code.
    Go to Dictionaries -> Local Dictionary -> Data Type - > Simple Type - > Right click and "Create Simple Type".
    Here you should create a Simple type with String as built-in Type. Here you will also see the Length Constraints option.
    Set the value of maximum length and minimum length. In your case set the value of maximum length to 10. At runtime this will not allow the user to enter more than 10 characters.
    Now create an attribute and bind it to this newly created simple type. Bind the value of the input field with this particular attribute.
    Regards
    Manohar

  • Any way to limit the input format for string control?

    Hi there,
      I need a control for the user to input some string with only alphabets and no special characters. Also need to control the number of characters to input. I search it and see someone use Xcontrol to achieve that but I really have no idea how to get that. Any other way to get this function works on string input?

    prvs wrote:
    Dear Altenbach,
    The VI that you have posted in (Max8Discard.vi) in Limiting Input String Length
    limits the entry of string control to required length but it doesnt limit the entry of special characters.
    If you have any simple way to do the same it will be very helpful
    Thanks in advance...!!!
    Regards,
    Praveen PRVS
    Just change the check after the Lexical Class function.  If you just want numbers and letters, then use the In Range & Coerce function to check for class numbers 3 through 5.  Play around with the logic some more until you get what you need (I'm thinking that AND should be an OR).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • A problem about a string length of the JTextField.

    Hi, all.
    I have a problem of check the length of the text in the JTextField. Look at the following program snippet.
    import javax.swing.text.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.DocumentListener;
    import javax.swing.event.DocumentEvent;
    public class test extends JFrame
    JTextField jTextField1 = new JTextField(50);
    static final int MAX_LENGTH = 10;
    public static void main(String[] asArgs)
    test testFrm = new test();
    testFrm.setVisible(true);
    class newDocument extends PlainDocument
    public void insertString(int offs,String str,AttributeSet a) throws
    BadLocationException
    String strTmp;
    strTmp = jTextField1.getText();
    int nSize1 = strTmp.getBytes().length;
    int nSize2 = str.getBytes().length;
    if(nSize1 + nSize2 > MAX_LENGTH)
    return;
    else
    super.insertString(offs,str,a);
    public test() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception {
    jTextField1.setText("");
    this.getContentPane().add(jTextField1, BorderLayout.NORTH);
    newDocument myDocument = new newDocument();
    jTextField1.setDocument(myDocument);
    public void removeUpdate(DocumentEvent e)
    jTextField1.setText(sOldStr);
    System.out.println("removeUpdate");
    Attention please: I want to check the bytes of the inputted string. It is no problem with english string inputting, but if I input a string with other charset such as A Japanese string or a Chinese string, it doesn't work(when your input string is as long as the MAX_LENGTH, it doesn't work well). How can solve it? Thank you very much.

    i believe the problem is that you didn't set the font of the JTextField.
    I don't know what's the default Font of the JTextField is (i think it's dialog)
    the default textfield cannot display chinese character (and mort unicode character - latin 2 - extends and above).
    You need to set the font that can handle displaying the CHinese & Japanese characters (however, your application may not work if you port your app to another computer..and they don't have the font that you specified (unless you ship the font with it))
    // why are you getting converting the String to byte and then get the length???
    int nSize1 = jTextField1.getText( ).length();

  • How to increase the string length of an uploaded file

    Hi,
    i use a abap webser where i've uploaded some JAR files into the mime repository.
    Unfortunately the string length is limited by 40 characters and so longer file names are cut.
    How can I increase the default string length? Does somebody know a workaround?
    Thanks.
    Edited by: Martin Gardyan on Oct 22, 2008 9:48 AM

    what i guess copying those jars should not create this problem.U just try in db using
    "ALTER TABLE <table_name> MODIFY <column_name> VARCHAR2(<new, larger length>)"
    may be it works.
    Regards,
    Anu

  • Event.rc and Restriction of inputs from the User...

    Im using Adobe Professional Live cycle designer 7.0 to design pdf form. Also, Im using an existing pdf (supplied by the customer), which is designed through teleform designer (with adobe 6.0) model for this design. In the existing one, the javascript methods are working fine for restricting keys, validation, etc. But these scripts are not working in designer as the designer is using XFA model.
    Im trying to restrict the key inputs (like only numbers/characters should be entered). But I couldnt find the equivalent statements for some of the statements (which are used in the teleform pdf).
    For eg.
    event.rc = true. Allows keystroke to be added to entry. event.rc = false. Prevents keystroke being added to entry in the following function:
    function TFTemplate_KeyStroke( mask )
    if (event.willCommit) {
    return;
    var value = AFMergeChange( event );
    if (!mask.test( value )) {
    event.rc = false;
    app.beep( 0 );
    But I couldnt find the matching statements in Designer for event.willCommit, AFMergeChange(),event.rc, etc.
    If I get, I can restrict the inputs.
    Expecting any solutions from you...
    Thanks in Advance...

    Hi,
    Based on your description, I understand that you want to use application or some functional tools and then
    monitor the user printer job. When be greater than a certain number, it will need to acquire additional information. As I know, it seems that there is no such function can meet your requirement. Sorry for it.
    In addition, I find that you use a third-party software for this functionality before. Please check and confirm
    if you can get a new version (or some updates, service package) that may help it to be supported in Windows Server 2012.
    Hope this helps.
    Best regards,
    Justin Gu

  • How to use DB toolkit to input string 255 into ACCESS Database

    I am converting an existing LV-Application from LV5.1.1 w/SQL toolkit to LV7.1 with DB-Conn. Toolkit.  One of the tables in my MS-Access database has a field of TYPE=memo (allows string lengths > 255 characters).  I can't seem to find how to insert this field in the DB-table using the "DB Tools Insert Data.VI" without getting an error.  I have tried converting the input string to a [U8] array, but that also doesn't work.  Just inputing the long string (390-chrs) also gives an error.  Reducing the string length to < 255 allows the new record to be input into the table without errors.  However, I need to be able to input the longer strings for the application to work.
    Does anyone have a solution to this problem.
    Thanks,
    Jim Cardinal

    Something like this
    David
    Message Edited by David Crawford on 01-12-2006 11:53 AM
    Attachments:
    Insert Text to Memo Using DBT.jpg ‏14 KB

Maybe you are looking for