Note that there are some explanatory texts on larger screens.

plurals
  1. PORegEx String Validator
    primarykey
    data
    text
    <p>In my MVC3 application, on one of the entities I am saving the <em>Date of Birth as a string</em>. Why ? because my application allows the storage of the date of birth of people long dead, eg. Socrates, Plato, Epicurus ... etc and as far as I know the DateTime class doesn't allow that.</p> <p>Now obviously we don't know the exact date of birth of Epicurus for example, we just know the year of birth [ 341 BCE ], so what I am thinking of doing is building a custom validator, that will validate the input string for the Date of Birth and make sure that they all match the following format:</p> <pre><code>12 Feb 1809 Feb 1809 341 341 BCE Oct 341 BCE 11 Mar 5 BCE </code></pre> <p>I would greatly appreciate it if someone can help me with a regular expression that will match any of the above, and of course not match anything else.</p> <p>I've been trying for hours, and not getting anywhere :s</p> <p><strong>UPDATE IN RESPONSE TO PROVIDED ANSWERS:</strong></p> <p>Thank You very much guys, I wish I was as good as you lot in building RegExes ! Since my application is with ASP.net MVC3, I would like to stick with the .NET RegEx class (for convenience's sake).</p> <p>luastoned answer seems to work !! I can't seem to break its logic with all the test data I've thrown at it.</p> <p>One thing though, can I also allow BC ? cause some people use BC and others use BCE &lt; would that be possible ? And .. am I right that the regular expression can not replace BC with BCE ? I have to do that manually through my C# code correct ? the RegEx would just either Match or Not .. correct ?</p> <p><strong>UPDATE TWO:</strong></p> <p>M42's Regular Expression seems to be working better. I've just copied it and used it in my Custom Validator (code in PasteBin link below).</p> <p>Thank You.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload