Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need regex to control input template 2numbers-space-2letters-space-3numbers

I need regex that controls "00 XX 000 " pattern
please help

private fun isTransferDescriptionValid(description: String): Boolean {
    val regex = "^[a-zA-Z0-9] [a-zA-Z0-9-/,. ][a-zA-Z0-9]\$".toRegex()
    return description.matches(regex)
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use, which would find 00 XX 000

\s is a gensral placeholder for space

val regex = "^[0-9]{2}\s[a-zA-Z]{2}\s[0-9]{3}$".toRegex()

then there is also [:space:]

val regex = "^[0-9]{2}[[:space:]]{1}[a-zA-Z]{2}[[:space:]]{1}[0-9]{3}$".toRegex()

But sometimes only a literal space helps

val regex = "^[0-9]{2} [a-zA-Z]{2} [0-9]{3}$".toRegex()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading