Numeric only fields - InfoPath Dev
in

InfoPath Dev

Numeric only fields

Last post 02-07-2017 03:29 PM by dc330. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-09-2006 04:31 PM

    Numeric only fields

    Hi,
    Is it possible to restrict user to enter numeric values only in a textbox. There is an option for data type, but it will let you enter alpaha characters and then warns you when you try to submit the form.
    (Handling keydown/up events??)
    Thanks in advance guys
    :)
  • 02-09-2006 07:43 PM In reply to

    Hi,
    Using screen Tip or placeholder we can direct user to only enter numeric values.
    After selecting data Type as whole number for a text box, if we enter characters, it will display red dashed bar in that textbox,
    I think this is fine to tell user to enter only numeric values,

    Thanks.

    K.Ramana Reddy
    Infopath Dev India
    K.Ramana Reddy / http://www.ggktech.com
    India.
  • 02-09-2006 10:02 PM In reply to

    Hi Vista_Live
    I dont think u can restrict users from entering non numeric values into the text box. However u can throw an alert to the user to enter numeric values only by writing code in the OnAfterChange event for the textbox.
    Steps involved
    1)Set the default value for the field as 0.

    2)Then write the following code in the OnAfterChange Event

    string checklist="abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_+={}[]|";
    char [] alphabet=checklist.ToCharArray(0,46);
    string strNumber=e.Site.text;
    for(int i=0;i<strNumber.Length;i++)
    {
    for(int j=0;j<alphabet.Length;j++)
    {
    if(strNumber==alphabet[j])
    {
    thisXDocument.UI.Alert("Enter a valid Number");
    e.Site.text="0";
    return;
    }
    }
    }
  • 02-10-2006 06:13 AM In reply to

    Why write custom code when you can just use the Data validation built in to InfoPath? If a field is invalid, InfoPath can issue a message box on it's own.

    Try this:

    1. Double-click the field
    2. Click Data Validation at the bottom of the dialog box.
    3. Click Add
    4. Select Does Not Match Pattern from the second drop-down box.
    5. Type the following custom pattern into the third drop-down "\d*".
    6. Type the message you want the user to see in the short and detailed error message fields.
    7. Select Dialog Box Alert from the drop-down.
    8. Click OK three times.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-10-2006 07:03 PM In reply to

    Thank you guys :)
  • 11-08-2008 04:30 PM In reply to

    Hi Abhishek

    I tried the above code in Infopath2003. it is giving me error.

    Suresh

  • 02-07-2017 03:29 PM In reply to

    • dc330
    • Not Ranked
    • Joined on 12-03-2009
    • Posts 23
    Yousa the boss Matt! That works perfectly!
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.