How can I achieve good validation check on String Input?

This is a portion of my code,am just starting to learn java programming.public class Thickness
public Thickness(){
public static void main(String[]args)
int thickness=0;
double length;
String strL;
strL=JOptionPane.showInputDialog(null,"Enter the length of your building:");
length=Double.parseDouble(strL);
while((length<4)||(length>12))
JOptionPane.showMessageDialog(null,"Error!This Program only works for"+"\n"+"Building whose Length lies Between 4m and 12m:");
strL=JOptionPane.showInputDialog(null,"Enter the length of your building:"+"\n"+"Note that Minimum Length is 4m:"+"\n"+"Maximum Length is 12m:");
length=Double.parseDouble(strL);
So that if the user enters a length outside the specified range of values the error message,"Error!This Program only works for"+"\n"+"Building whose Length lies Between 4m and 12m:" will be displayed and the program will prompt the user to re-enter the length.
This validation check works perfectly as long as the input is double or integer,What I need now is to include a check to display an error message if the user inputs nothing or supplies a character (other than integer or double)as input.I want to be able to customise the error message,like having(JOptionPane.showMessageDialog(null,"Error!This is an invalid input:")).
I know the compiler will also generate an error message if the user inputs a String instead of a double,but I want to be able to achieve this instead of the compiler doing it for me.
pls I will be very happy if you can assist me with the code that would perform this check.
Thanks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

length=Double.parseDouble(strL);Read the API. It tells you that it can throw some kind of exception if the input isn't valid. Then it's up to you to properly handle the exception. If you don't handle it, the VM does by displaying the exception and terminating the app.
API docs:
http://java.sun.com/j2se/1.5.0/docs/api/index.html
Tutorial on exceptions:
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

Similar Messages

  • How can i add multiple validations for a single input box in adf?

    hi,
    i want to add multiple validation for a single input text control in adf like number validation and its existence in database.
    MY JDEV VERSION IS 11.1.1.5.0
    pls help !!!!

    Hi,
    1.I want to validate if the value entered is pure integer
    Option 1-
    select the component and in the Property Inspector, in the "Core" category select a "Converter" format, select javax.faces.Number, if the user put a string, adf show a dialog error or message error...
    Option 2-
    or use the Regular expression:-
    http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_validateRegExp.html
    https://blogs.oracle.com/shay/entry/regular_expression_validation
    Also check this:-
    http://docs.oracle.com/cd/E15523_01/web.1111/b31973/af_validate.htm#BABHAHEI
    Option 3-
    Frank in his great book 'Oracle Fusion Developer Guide' shows a example using a javascript for input which is allowed only for numbers. You can manipulate for your requirement.
    Here is the code:
    function filterForNumbers(evt) {
        //get ADF Faces event source, InputText.js
        var inputField = evt.getSource();
        var oldValue = inputField.getValue();
        var ignoredControlKeys = new Array(AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.TAB_KEY, AdfKeyStroke.ARROWLEFT_KEY, AdfKeyStroke.ARROWRIGHT_KEY, AdfKeyStroke.ESC_KEY, AdfKeyStroke.ENTER_KEY, AdfKeyStroke.DELETE_KEY);
        //define the key range to exclude from field input
        var minNumberKeyCode = 48;
        var maxNumberKeyCode = 57;
        var minNumberPadKeyCode = 96;
        var maxNumberPadKeyCode = 105;
        //key pressed by the user
        var keyCodePressed = evt.getKeyCode();
        //if it is a control key, don't suppress it
        var ignoreKey = false;
        for (keyPos in ignoredControlKeys) {
            if (keyCodePressed == ignoredControlKeys[keyPos]) {
                ignoreKey = true;
                break;
        //return if key should be ignored
        if (ignoreKey == true) {
            return true;
        //filter keyboard input
        if (keyCodePressed < minNumberKeyCode || keyCodePressed > maxNumberPadKeyCode) {
            //set value back to previous value
            inputField.setValue(oldValue);
            //no need for the event to propagate to the server, so cancel
            //it
            evt.cancel();
            return true;
        if (keyCodePressed > maxNumberKeyCode && keyCodePressed < minNumberPadKeyCode) {
            //set value back to previous value
            inputField.setValue(oldValue);
            evt.cancel();
            return true;
    2.I want to check if the value exists in my respective DB You must be having EO or VO if you want to validate with database in that case use the solution suggested by Timo.
    Thanks
    --NavinK                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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

  • HOW CAN APPLY FREE GOOD 4 PRICING PROCEDURE?

    TELL ME SIR HOW CAN APPY FREE GOOD 4 PRICING PROCEDURE?

    Hi Pradeep
    1.Run trans. VBN2 to first create master record for free goods as follows:
    Enter following information in selection screen:
    - Free goods type: NA00
    - Sales org, distribution channel, customer # and execute.
    Now in next screen create the record as follows:
    - First select the exclusive button and verify that you are in exclusive view. 
      (that is if you want exclusive)
    - Material#, Min qty - Say 34 cartons. (check in what units you want to manage)
      From: 34 cartons
      unit of measure: 
      Free goods: 12 Pcs
      Unit of measure: Pcs
      Calcualtion type: 1 or try the other options
      Deliver control: Blank or any of the other options suitable to you.
    Now save and exit.
    Now run VA01 for 34 cartons and press enter. The system will automatically propose the free goods 
    item at no additional charge. Try higher order qtys and see if the free goods qty are scaling up. 
    If not adjust the calculation parameters in the master record screen
    It should be transaction VBN1. Sorry for the error. 
    VBN2 is to change the record. VBN1 creates it.
    If you want to give free goods to some of the customers than
    1. create a customer group say 99 for FREE GOODS
    In Free Goods Menu:
    2. add a feild catalog for CUSTOMER GROUP
    3. create a condition table (free goods) say 555 only for customer group
    4. create a sequence say FREE with condition table 555
    5. create a condition type say FREE with
    6. maintain pricing procedure say ZFREE with condition type FREE
    Now assign:
    7. Active Free goods Determination or Assign with your sales organisation this procedure ZFREE
    8. Create free goods determination with transaction code /nvbn1 for FREE with Key Csuomer Group 
    99 for exclusive
    Give customer Group say 99 and from 34 to 34 free 12
    Thanks
    G. Lakshmipathi

  • How can i achieve Outerjoin type of results using Reports Datalink option

    Hi,
    i am developing a Oracle Report. i am using Datalink to maintain parent-child relationship between 2 queries. If no matching value found then i want to return 0 Records. how to achieve this.
    Ex: I have 2 tables like Dept & EMP
    DEPT has 2 rows HR and FINANCE
    I have only one employee in HR and no employee in FINANCE.
    I am using the below datalink properties:
    SQL clause : WHERE
    CONDITION ; =
    PARENT GROUP: DEPT
    PARENT Column : DEPTID
    CHILD QUERY : EMP
    CHILD Column : DEPTID.
    In the report it is showing matching columns without any issues> i want non matching columns also with Zero employess like
    HR     1
    FINANCE 0
    I need OUTER JOIN kind of thing. How can i achieve this. Just i have written one example. I have very complex query to implement this and datalink is absolutely necessry for me. Any help please.

    Following can be checked in order to return column value from child Group to Parent Group at data modal.
    a. create a PlaceHolder column ( say CP_1 and CP_2) at parent Group.
    b. create one Formula column at each Child group ( say cf_1 and cf_2 )
    c. write code at formula to return reg_emp as ( say for cf_1)
    srw.reference(:cp_1);
    :cp_1 := :rep_emp;
    for unreg_emp as
    srw.reference(:cp_2);
    :cp_2 := :unreg_emp;
    .. this way now reg_emp and unreg_emp counts can be made available to parent Group.
    To get a difference and return "Yes" or "No" write formula column at Parent Group ..
    Create a Formula column ( say cf_3) at parent group
    write following
    begin
    if :cp_1 = :cp_2 >0 then
    return 'Yes';
    else
    return 'No';
    end if;
    end;
    Now use this formula as source to show value at layout under Parent Repeating Frame.
    Hope this helps..

  • I was login a website ,and i have opened cookies , i want to open another window to login the same website use another account , and in the same windows can use the same account , how can i achieve it ? thinks

    i want to use firefox to login a website ,in the same window and different tags can user the same session
    but when i open other window and login the same website use different account .
    how can i achieve it ? thinks

    Your problem has nothing to do with the faults or limitations of a web browser.
    ''There can be only ONE active user logged in on a specific website during a whole Browsing Session. Even if you try to log-in using a new window it will sign-out the earlier User ID from that website. It will keep the most recent logged-in User ID active.''
    This is the general policy on which all websites are built. Even if you try to login the same website from another web browser, you won't be able to login from the second platform either. I just check it. Tried on Mozilla and Internet Explorer.

  • How can i achieve tis in Bex Query Designer

    Hi Experts,
    Please advise on how can i achieve this in Query.
    I got Location,Material_ID,Price and Change_Date.
    (Change_Date is defined as both CHAR & KF in cube)
    (Change date is on monthly basis they execute a programe in non sap source system to update the prices of material)
    The Price of material tends to change or may not change ...
    Every month we get a record from source system on material price
    My requirment is to bulid a report that show
    LocationMaterial_IDCurrent Price  and Previous Price
    Please advise how can i develop this report

    While loading into cube, normally you map  price field coming from datasaource to
    infobject  ZPRICE_CURRENT   in your infocube.
    So in transformation you map like this
    price  -
    > ZPRICE_CURRENT
    Now, Maintain another keyfigure in cube  ZPRICE_PREVIOUS.
    That is not mapped with anything.But is assigned a value in the Start routine
    which just runs before, the transformation.
    In the start routine write code something like this :
    Read current value of price from cube for that Material.
    (Select  ZPRICE_CURRENT into price_curr  from cube where material = DATA-PACKAGE- Material   )
    if  DATA_PACKAGE-price <> price_curr   ( if new_price <> old_price)
    ZPRICE_PREVIOUS = price_curr. (storign present value of price in the cube )
    endif.
    Now save the Start routine. When mapping the fields in the transformation
    dont map anythign to  ZPRICE_PREVIOUS as it is already filled in teh start routine from the above  code.Leave it unmapped.
    The below mapping is normally maintained without change..
    price  -
    > ZPRICE_CURRENT
    If you find this to be useful ..please do the needful (points)

  • How can i remove the spell check from my iMac, i tried system pref but it still autocorrects

    how can i remove the spell check from my iMac, i tried system pref but it still autocorrects

    Look at the Spelling settings in the Edit menu of the app that is doing the correcting.

  • I want to delete my current exchange account. How can I achieve this and not lose stored information such as contacts, photos etc. please help. Thank you.

    I want to delete my current exchange account and replace it with my new one. How can I achieve this and not lose my contacts, photos, etc associated with this account? Please help..
    Thank you,

    Bad idea.
    What information do you want to share, exactly?  You can share contacts, reminders, and calendars with other iCloud users without the need for both of you to use the same iCloud account.  You can authorize both phones to use apps purchased under the same Apple ID without sharing an iCloud account.
    Sharing an iCloud account is a bad idea in general. There is too much opportunity for someone to damage or delete data that will affect both.

  • How can we do the validation for non visible records in table control.

    Hi Experts,
      I have a table control which displays list of material details. I have a button to upload the material details from excel file to table control directly. I have to validate all the customers which are exist in the table. But my item (Material) table control displays only 5 rows i.e only 5 entries are visible in module pool screen. The validation is done for 5 records only in PAI event, but i need to do validation for rest of the records too (Which are not visible on items table), if validation fails then needs to display error message.
      How can we do the validation for non visible records in table control.
    Regards,
    Bujji

    Hi,
    try validating material before displaying it in table control...'
    Rgds/Abhhi

  • Sorry - Could you please help me how can I achieve this Search help ?

    I am creating search help for the profit_center field,
    For the search help :
    The scenario is I have three Z-tables.
    Example: The Data in tables are as shown below ( where F1, F2 are the fields ).
    Ztable1
    F1
    A
    B
    C
    D
    Ztable2
    F1 F2
    A 1
    A 2
    B 112
    B 113
    C 34
    D 43
    D 55
    D 87
    Ztable3
    PRCTR F1 F2
    123 A 1
    124 A 2
    123 B 112
    124 B 113
    125 C 34
    123 D 43
    124 D 43
    125 D 43
    I need to create search help (Search Help is similar to Collective Search Help) for the field PRCTR of table Ztable3 like as below.
    By pressing F4 on the field, a pop up should appear which should contains text labels& text fields on TAB-Screen ( A, B, C , D as shown below as text lables )against which text fields should appear.
    TAB-Screen :
    A ____________
    B ____________
    C ____________
    D ____________
    If F4 is pressed on I/O field (text fields) against A in the above TAB-Screen, Corresponding values ztable2-F2 of A from ztable2 ( = 1, 2 ) should appear as F4 help.
    so that user can select ...
    Is it possible to acieve this ? It would be a great help ....How can I achieve this ?
    Finally based on above user selections say
    A ____________
    B ____________
    C ____________
    D ____________
    corresponding prctr values should be collected.

    <b>You can acheive   this .... first by creating the search help exit    ... by  creating the maintaince  view   then   using it in the   Creation of the search help </b> ...
    see the link for attaching the view   to the serach help .
    <a href="http://">http://www.sapdevelopment.co.uk/dictionary/shelp/shelp_elementary.htm</a>
    reward  points if it is usefull...
    Girish

  • How can I use SQL to check if the receipt is accounted?

    Dear all:
    How can I use SQL to check if the AR receipt is accounted ? Because there is so many receipts to check, I cannot open it to see the detail one by one.
    My environment is :11.5.9
    database : Oracle 9.2.0.8

    Duplicate post.
    How can I use SQL to check if the receipt is accounted?
    Re: How can I use SQL to check if the receipt is accounted?

  • How can i creat CRC 32 CHECK WITH THE lookup table as attached.

    how can i creat CRC 32 CHECK WITH THE lookup table.attached
    i creat one,but not match the result number C++ version
    result number C++ version:
    FE 00 18 02 40 1E 65 43 00 03 E8        CRC32=>78 1F E9 06
    FE 01 18 02 40 1E 65 43 00 03 E8        CRC32=>F8 8F 49 61
    FE 02 18 02 40 1E 65 43 00 03 E8        CRC32=>7D FF B4 7F

    due to some reason i can not attach the table.but you can find it herehttp://lavag.org/topic/15325-crc32/,it in the CRC.llb 84.03K =>CRC-32 Table.ctl thanks a lot

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • How can I convert  an ArrayList to a String[]

    Hi,
    How can I convert an ArrayList (only with strings) to a String[] ?
    I've tried this :
         public static String listToString(List l) {
              StringBuffer sb = new StringBuffer();
              Iterator iter = l.iterator();
              while (iter.hasNext()) {
                   sb.append(iter.next().toString());
                   if (iter.hasNext()) {
                        sb.append(',');
              return sb.toString();
    But what I get is an array of xxxxx@435634 (for example).
    Thanks a lot !

    Strings are Objects but not all Objects are Strings and at least one of the elements in your List is not a String.

Maybe you are looking for

  • Disk Repair Needed?

    I have a Macbook Pro, 500 GB Hard drive, core i7 Processor. I was trying to delete old backups from one of my other computers in order to make space for new backups on my MBP. I dragged the old backups to the trash, because I did not want to reformat

  • PO BAPI Problem in condition types

    Hi, I am facing a strange problem in creation of PO through "BAPI_PO_CREATE1". In the Item condition internal table, I am passing the condition types. The PO is getting created successfully. Eg. I pass conditions and their values as follows: PB00 : 1

  • Multy-Level flash chart in WD4A

    I have been using flash charts in my Web Dynpro components for a while now and I thought it's time to try and take it to the next level and create an interactive chart. I got a request from my user for a graph with 2 levels - a weekly level that show

  • Change of Mapping Drives in my system

    Dear Sir please help me, i could not install the latest version, it was saying that error please change the mapping G Drive, how could i change the mapping of drive from Gdrive to Cdrive??

  • Shipment with multiple vendors

    Dear All, My business requirement is 2 service vendors are involving is shipment process one vendor will supply the container and other vendor supply truck with under same route. shipment cost will be share between two vendors. what are configuration