How to generate pattern to validate date input using regular expressions in Excel?

These templates cover all types of characters that are entered during encoding Visual Basic to symbolize an error in the event of a change in the content.

In this way we explain the group of characters that make it up and how you can write the pattern that will allow you to validate the dates you enter in Excel.

What is the pattern you should establish for dates?

When generate the template to validate the date entry, you need to know what symbols, numbers and letters you will write in order for the code to be read correctly and the function to perform as expected.




The code you need to establish within the form is the following:

  • “^ ([0] [1-9] | [12] [0-9] [3 [01]) ( / | -) ([0] [0-9] | [1] [0-2]) 2 ( d {4}) $ “

The symbol of disjunction " ^ ”Must always be at the beginning of the string, which is responsible for indicating that one or more sequences can be given, but not all at once.

Definition of the code established to generate the template to validate the date insertion

Since the dates are presented in the form of day, month and year and have a degree of variability, this is what will establish the number of sequences that will be written in the code.

How to generate pattern to validate date input using regular expressions in Excel?

 

Days of the month

In the case of the days we know that in the calendar have a variation from 0 to 30 (or 31 depending on the month), so you need to put together three types of sequences:



  • The first which includes numbers starting with the number 0 and can culminate from 1 to 9.
  • The second which includes numbers starting with the number 1 and can culminate from 0 to 9.
  • The third and last, which includes numbers starting with the number 3 and ending between 0 and 1.

To set up sequences. The brackets open to write each of the sequences in brackets to establish the main number and the number that will be accompanied by to create the day format.


Month of the year

Once the above is done, the valid separators that can be inserted by the person, in the case of symbols " /The - " between brackets, starting with a backslash.

With the months the sequences are established in the same way as the days of the week, establishing both sequences with numbers that can go from 0 to 12.

  • The first sequence will be established with numbers starting with 0 and can culminate from 1 to 9.
  • The second sequence will be established with numbers starting with 1 and can culminate from 0 to 2.

 

Again you have to re-enter the separators in the same way you did for the first time. Or simply add " 2 "Indicating that what is written must match the second group established in the macro code.


Date year

In this last part you have two options. Or add sequences in the same way as a large number of years it can be extended to the date it can be written.


How to generate pattern to validate date input using regular expressions in Excel?

Because this takes a lot of numbers. The process is simplified by using brackets around the term " d ”Indicating any existing decimal number.


Since it does not help us to consider an infinite number, it must be established that they will be limited to a format of four characters by " 4 {} ".

Finally, it indicates that you have finished the sequences by adding the symbol " $ " it's done!

If you are interested in working properly in Excel. We recommend that you know all the functions that this program offers you and that make your work easier. If you plan to work with graphics, learn how to create a legend or create the graphics using macros.

If you want to privately save and hide an Excel sheet you can also do it via macro.

TagsEccellere
add a comment of How to generate pattern to validate date input using regular expressions in Excel?
Comment sent successfully! We will review it in the next few hours.