Validating a field

FreakyFreaky Member Posts: 125
Hi Guys,
I posted a similar question some time and now I want it in a different way. I have this field called "Employee No." on a form called the Employee card. I want a validation such that I only want to insert 7 digits and the first digit must not be greater than 3. If the number is less than or greater than 7. I will have an error message and if the first digit of the 7 digits is greater than 3 an error message also. Please I just need the codes on how to do this.

Thanks in advance.

Comments

  • SavatageSavatage Member Posts: 7,142
    Just to be clear..
    1)"Employee No" is type code correct
    2)you want a seven digit Employee No.
    3)the first digit must be 0,1,2,3

    is this correct?
    How about on validate of the employy no field...
    OnValidate()
    IF STRLEN("Employee No.") <> 7 THEN ERROR('Employee No. Must Have 7 Digits');
    IF COPYSTR("Employee No.",1,1) IN ['4','5','6','7','8','9'] THEN ERROR('First Digit Of Employee No. Must Not Be Greater Than 3');
    

    I bet there will be alternate codes :)

    Here's the link to your other post
    viewtopic.php?f=23&t=28251
  • FreakyFreaky Member Posts: 125
    Thank you.. That worked.. Now i want to add new validation. The Length of the field as usual is 7. I want to check within the filed if there is any alphabet it rejects it and display the message it cannot take alphabet. How best can i do this?
  • SavatageSavatage Member Posts: 7,142
    I'm at home now so I can't check but i believe if you look at the properties of the field there should be one called CharsAllowed or something like that - fill that with 0123456789
  • FreakyFreaky Member Posts: 125
    Thanks Savatage that really helped. :)
  • SavatageSavatage Member Posts: 7,142
    Yeah works like a charm that charsAllowed :) _ if you edit your first post you can change the attribute on top to SOLVED.
  • MalajloMalajlo Member Posts: 294
    Try this:
    Pos := 0 ;
    REPEAT
      Pos := Pos + 1 ;
      IF COPYSTR("Employee No.",Pos,1) IN['A'..'Z'] THEN ERROR('Only numbers allowed"') ;
    UNTIL Pos > STRLEN("Employee No.")
    
Sign In or Register to comment.