Forcing Alpha Character Entry

NavTimeNavTime Member Posts: 18
I have a code field and my client requires an error if anything but an alpha character is entered. Does anybody have any experience or idea how to approach this? Thanks for the help.

Answers

  • JDVyskaJDVyska Member Posts: 179
    edited 2009-07-15
    This should help you along your way.
    OBJECT Form 50900 ValidateLetters
    {
      OBJECT-PROPERTIES
      {
        Date=07/14/09;
        Time=[ 1:53:03 PM];
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=8000;
        Height=8000;
      }
      CONTROLS
      {
        { 1000000000;TextBox;4510 ;550  ;1700 ;440  ;SourceExpr=TestInput;
                                                     OnValidate=BEGIN
                                                                  Valid := LetterValidate(TestInput);
                                                                END;
                                                                 }
        { 1000000001;Label  ;1100 ;550  ;3300 ;440  ;ParentControl=1000000000 }
        { 1000000002;TextBox;4510 ;1210 ;1700 ;440  ;SourceExpr=ResultASCII }
        { 1000000003;Label  ;1100 ;1210 ;3300 ;440  ;ParentControl=1000000002 }
        { 1000000006;CheckBox;4510;2090 ;440  ;440  ;ShowCaption=No;
                                                     SourceExpr=Valid }
        { 1000000007;Label  ;1100 ;2090 ;3300 ;440  ;ParentControl=1000000006 }
      }
      CODE
      {
        VAR
          TestInput@1000000000 : Text[30];
          myChar@1000000001 : Char;
          ResultASCII@1000000002 : Integer;
          Valid@1000000003 : Boolean;
    
        PROCEDURE LetterValidate@1000000000(Text@1000000000 : Text[100]) : Boolean;
        VAR
          i@1000000001 : Integer;
        BEGIN
          FOR i := 1 TO STRLEN(Text) DO BEGIN
            myChar := Text[i];
            ResultASCII := myChar;
    
            IF NOT (myChar IN [65..99,97..122]) THEN
              EXIT(FALSE);
          END;
          EXIT(TRUE);
        END;
    
        BEGIN
        END.
      }
    }
    
    


    Char is your friend in this case, most likely.
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • NavTimeNavTime Member Posts: 18
    edited 2009-07-14
    Awesome. You the man!!! Thanks!!!!
  • JDVyskaJDVyska Member Posts: 179
    edited 2009-07-15
    Cool. Edit the 1st post and mark it [Solved] (drop box right below Subject).
    :thumbsup:
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • SavatageSavatage Member Posts: 7,142
    How about the property of the field -> CharAllowed.

    enter AZaz
  • JDVyskaJDVyska Member Posts: 179
    edited 2009-07-15
    ^ MVP right answer trumps my 'would work' function.
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • NavTimeNavTime Member Posts: 18
    It works too but I need to control the error message so the first solution works better for me.
  • SavatageSavatage Member Posts: 7,142
    There are usually multiple ways to skin-a-cat w/Nav 8)
  • NavTimeNavTime Member Posts: 18
    Thanks for both solutions.

    Question to MVP... how did you know to specify AZaz? Where did you get that information? I tried that property but didn't know what values to supply it with.
  • JDVyskaJDVyska Member Posts: 179
    edited 2009-07-15
    If you go into the properties of the Form Textbox or the table's field, you'll see CharAllowed in the list. F1 in that field brings up the info:
    If you want users to only enter uppercase letters in this field, enter AZ. This ensures that only uppercase characters in the range of A-Z are accepted. If you want both uppercase and lowercase characters, leave this value blank.

    You can specify multiple ranges of characters by entering the parameters in pairs. For example, a value of admpzz indicates that only the following characters are accepted: a, b, c, d, m, n, o, p, and z. If you only want to allow a single character, then enter that character twice to specify a starting and ending range.

    For text boxes, you can use this property to further limit the characters allowed, based on the field's setting.

    The setting for the text box and the field is checked during validation.

    I've never had to use it, so I looked it up also. :mrgreen:
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • NavTimeNavTime Member Posts: 18
    I did the same but F1 didn't come up with the same help text for me. Is there something else I need to do get that same help text as you?
  • SavatageSavatage Member Posts: 7,142
    click on the property name "CharsAllowed" & hit F1

    the help says AZ
    If you want users to only enter uppercase letters in this field, enter AZ

    so I threw in the lowercase az to cover my bases :lol:
  • JDVyskaJDVyska Member Posts: 179
    NavTime wrote:
    I did the same but F1 didn't come up with the same help text for me. Is there something else I need to do get that same help text as you?

    If you're using a version that isn't NAV2009, F1 in field properties often just drops you at the generic "Welcome to Microsoft Dynamics NAV Online Help". But if that's the case, this thread, while still accurate, should live over there. :wink:

    Open the Help menu, and go to C/SIDE reference. Search tab, type 'CharAllowed' and search. There be the help text you seek.
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV 2009' forum to 'NAV/Navision' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.