Skip to content

Instantly share code, notes, and snippets.

@jamesdube
Last active February 5, 2024 14:29
Show Gist options
  • Save jamesdube/479842b73044b88bbb1399b52ceb92f5 to your computer and use it in GitHub Desktop.
Save jamesdube/479842b73044b88bbb1399b52ceb92f5 to your computer and use it in GitHub Desktop.
Zimbabwe National ID Regex
# 00000000X00
/([0-9]{8,9}[a-z,A-Z][0-9]{2})/g
# 00-000000-X-00 dashes are optional
/([0-9]{2}-?[0-9]{6,7}-?[a-z,A-Z]-?[0-9]{2})/g
# 00-000000 X00 dash is required, space before letter is optional
/([0-9]{2}-[0-9]{6,7}\s?[a-z,A-Z][0-9]{2})/g
@makone93
Copy link

Makaipa mdhara

@jamesdube
Copy link
Author

Makaipa mdhara

Thanks mate

@Tawa-dev
Copy link

Thanks, just made my day.

@Comfie
Copy link

Comfie commented Dec 9, 2021

Nice one baba.

@tzifudzi
Copy link

tzifudzi commented Mar 1, 2022

Thanks. Saved me a couple of hours.

@user3470
Copy link

user3470 commented Mar 17, 2022

Une yese wangu

  const ID = (S(message.text).replaceAll(' ', '').trim().s).toUpperCase(); // const S = require('string')
  //Format: 00-00000X00
  const re = /^\d{2}\-\d{6,8}[A-Z]{1}\d{2}$/;
  if (!re.test(ID)) throw "Invalid Format";

@TheArtifulProgrammer
Copy link

Kuddos

@innocent-george-mithu-nyamusa

Just made things a whole lot easier.

@percym
Copy link

percym commented Dec 15, 2022

if you are doing it in Java then

Pattern pattern = Pattern.compile("\d{7,9}[A-Z]{1}\d{2}$");
@OverRide
public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException {
log.info("posted id number {}", o.toString());
Matcher matcher = pattern.matcher(o.toString());

    if (!matcher.matches()){
        FacesMessage msg =
                new FacesMessage("Invalid Id Number","Check the id number that you input");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);
    }
}

@englontribetron
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment