Introduction This article explains how to use Regex in a Windows application. The code example uses Regular Expressions in C to validate name, address, and telephone number input by a user.
Before we look at the code sample, I would like to provide a little explanation of Regular Expressions. Regular Expression Regular Expressions are specially formatted strings for specifying patterns in text. They can be useful during information validation, to ensure that data is in a specified format.
For example, a ZIP code must consist of five digits, and the last name must start with a capital letter. Compilers use Regular Expressions to validate the syntax of programs. If the program code does not match the Regular Expression then the compiler indicates that there is a syntax error.
Let's go for the details of my illustration. When a user clicks the OK button, the program checks to ensure that none of the fields are empty. If I got anything wrong or missed an important piece of information, please correct me. ZF 3, 8 8 gold badges 30 30 silver badges 45 45 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 0. See more linked questions. Related Hot Network Questions. This quantifier will ensure that our expression will match all variations the 9-digit ZIP code, but also the simple 5-digit code.
ZIP codes are numeric in nature, and may contain a dash of a space. Therefore, the case insensitive flag i would not be of any use here. In this case, however, you should also remove the start-of-string and end-of-string characters:.
The regular expressions on this page were adapted from solutions posted on Stack Overflow by kennytm and Emma on this question. In addition, this article proved useful in understanding the general format of a ZIP code.
0コメント