Only Numeric Characters Allowed - InfoPath Dev
in

InfoPath Dev

Only Numeric Characters Allowed

Last post 10-19-2006 08:12 AM by Michael71. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-13-2006 07:55 AM

    • Michael71
    • Top 50 Contributor
      Male
    • Joined on 10-07-2006
    • Mclean, Virginia-USA
    • Posts 283

    Only Numeric Characters Allowed

    People,

    How do I prevent a user from entering in anything else except Numeric Characters in the TEXT Box?? I don't even want them to be able to type Numeric Characters in the text box.

    Michael
  • 10-13-2006 09:39 AM In reply to

    Re: Only Numeric Characters Allowed

    You should be able to do this with a custom data validation rule. It will still allow them to type the characters but will show red outline and a warning message when it happens.

    If you want to physically disable them from entering such characters you would need to use code in the OnBeforeChange event of the field. Check the NewValue to see if it has any numbers in it, if so, set it to the OldValue.

    I hope this helps, let us know if you need help with the details of either of these implementations.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-13-2006 10:30 AM In reply to

    • Michael71
    • Top 50 Contributor
      Male
    • Joined on 10-07-2006
    • Mclean, Virginia-USA
    • Posts 283

    Re: Only Numeric Characters Allowed

    Matt,

    I'm new at this. I need help with the OnBeforeChange event of the field. And to Check the NewValue to see if it has any numbers in it. Then I need to set it to the OldValue. Can you tell me how and give me some details. [EDIT: Removed issue discussed in seperate thread]

    Michael71
  • 10-13-2006 12:08 PM In reply to

    Re: Only Numeric Characters Allowed

    Hey Michael,

    I have seen you posting several duplicate topics as well as intermingling topics. Please try to keep the forum organized by refraining from these activities. Below is a sample code snippet of this functionality in C#.NET:

    // The following function handler is created by Microsoft Office InfoPath. Do not
    // modify the type or number of arguments.
    [InfoPathEventHandler(MatchPath="/my:CustomerAdmin/my:Customers/my:Customer/my:Contacts/my:Contact/my:Email", EventType=InfoPathEventType.OnBeforeChange)]
    public void Email_OnBeforeChange(DataDOMEvent e)
    {
    // Write your code here. Warning: ensure that the constraint you are enforcing is
    // compatible with the default value you set for this XML node.

    string[] badStrings = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    bool badNewValue = false;

    for (int i = 0; i < badStrings.Length; i++)
    {
    if (e.NewValue.ToString().Contains(badStrings))
    {
    badNewValue = true;
    break;
    }
    }

    if (badNewValue)
    {
    e.ReturnMessage = "You may not enter numeric characters in this field.";
    e.ReturnStatus = false;
    }

    }
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-19-2006 08:12 AM In reply to

    • Michael71
    • Top 50 Contributor
      Male
    • Joined on 10-07-2006
    • Mclean, Virginia-USA
    • Posts 283

    Re: Only Numeric Characters Allowed

    Do I change this.......

    [InfoPathEventHandler(MatchPath="/my:CustomerAdmin/my:Customers/my:Customer/my:Contacts/my:Contact/my:Email", EventType=InfoPathEventType.OnBeforeChange)]
    public void Email_OnBeforeChange(DataDOMEvent e)
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.