Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.