postcode format check. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

postcode format check.

sexyderrysexyderry Posts: 31Member
i am producing a program for a school project, and a validatiopn check is needed for a postcode. Need help!! considering a postcode is Letter,Letter,Number,Number,Letter,Letter.

i have tried reading the postcode into individual characters like postcode[1], and [2] and so on. but i cant seem to get it right. all help wuld be appreciated. thanks.

Comments

  • zibadianzibadian Posts: 6,349Member
    : i am producing a program for a school project, and a validatiopn check is needed for a postcode. Need help!! considering a postcode is Letter,Letter,Number,Number,Letter,Letter.
    :
    : i have tried reading the postcode into individual characters like postcode[1], and [2] and so on. but i cant seem to get it right. all help wuld be appreciated. thanks.
    :
    Here is a small code to check if the first and second characters are valid. It is quite simple to expand to more than those.
    [code]
    IsValid := Postcode[1] in ['a'..'z', 'A'..'Z'];
    IsValid := (Postcode[2] in ['a'..'z', 'A'..'Z']) and IsValid;
    [/code]
    The brackets () in the second line are necessary, due to the precedence of the boolean operator "and" (high) and "in" (low). The variable IsValid is a boolean.
  • sexyderrysexyderry Posts: 31Member
    : : i am producing a program for a school project, and a validatiopn check is needed for a postcode. Need help!! considering a postcode is Letter,Letter,Number,Number,Letter,Letter.
    : :
    : : i have tried reading the postcode into individual characters like postcode[1], and [2] and so on. but i cant seem to get it right. all help wuld be appreciated. thanks.
    : :
    : Here is a small code to check if the first and second characters are valid. It is quite simple to expand to more than those.
    : [code]
    : IsValid := Postcode[1] in ['a'..'z', 'A'..'Z'];
    : IsValid := (Postcode[2] in ['a'..'z', 'A'..'Z']) and IsValid;
    : [/code]
    : The brackets () in the second line are necessary, due to the precedence of the boolean operator "and" (high) and "in" (low). The variable IsValid is a boolean.
    :

    Aaaaaaah, its the brackets i was missing, thanks Zibadian.

Sign In or Register to comment.