ValidationExpression for a special date format - asp.net

I need to use the RegularExpressionValidator. It has to check the correct format. I have found this nice working expression:
^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
But I need this Expression not for dd/mm/yyyy. My date format should be dd.mm.yyyy.
How to transform this expression?

try it
/^(?:(0[1-9]|1[012])[\. \/.](0[1-9]|[12][0-9]|3[01])[\. \/.](19|20)[0-9]{2})$/
or
^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$

It look like only thing that need to be changes is all \/ to \. so it should be
^(((0[1-9]|[12]\d|3[01])\.(0[13578]|1[02])\.((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\.(0[13456789]|1[012])\.((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\.02\.((19|[2-9]\d)\d{2}))|(29\.02\.((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$

Related

Number format with Eval in ASP.NET

I would like to format this kind of number:
1234567.99 (obviously all thousands digits are optional)
In this way: 1.234.567,99
I know it is possible with Eval, but I didn't find an useful guide to do this.
Could you help me?
Thanks
There is an overload of Eval that takes three parameters (the link also contains a sample):
Container
Expression
Format
For the format, you'd specify "{0:c}" or whatever format you like. For a list of the Standard Numeric Format Strings, see this link. If you want to specify your format with a custom format string, e.g. use "{0:#,##0.00}".
You can use the ToString() extension
var value = 1234567.99;
Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));
Or by stating your culture
Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("sv-SE")));

Regular Expression format for 0000/123456/23

I have a text box for Registration Number and i want it to use the following format 2013/123456/25. I want to validate for in-correct format using Regular Expression Validator.
The exact format must be first 4 numbers/6 numbers/2 numbers -->(2013/123456/25)
Thank you for your help...
You could use something like this :
^\d{4}/\d{6}/\d{2}$

Regular Expression for Date Format : dd-mm-yyyy

I want to check the date which must be in the format dd-mm-yyyy using a regular expression, and it also must check the leap year dates.
I am using RegularExpressionValidator for checking the date.
try this. It works for me!
ValidationExpression="(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))-(((0[1-9])|(1[0-2]))|([1-9]))-(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)"
Try this regular expression-
^(((((0[1-9])|(1\d)|(2[0-8]))-((0[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0[1,3-9])|(1[0-2])))))-((20[0-9][0-9]))|(29-02-20(([02468][048])|([13579][26]))))$
Got it from Here
This regex also handles leap year:
^(((0[1-9]|[12]\d|3[01])/(0[13578]|1[02])/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)/(0[13456789]|1[012])/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])/02/((19|[2-9]\d)\d{2}))|(29/02/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
Matches
[29/02/2000], [30/04/2003], [01/01/2003]
Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]
You can also check this link out: http://www.codeproject.com/KB/aspnet/LengthValidation.aspx
You can javascript to check leap year for more info
isLeap = new Date(year, 1, 29).getMonth() == 1
Regular Expression
^(?:^(?:(?:(?:(?:(?:0?[13578]|1[02])/31)|(?:(?:0?[13-9]|1[0-2])/(?:29|30)))/(?:1[6-9]|[2-9]\d)\d{2})|(?:0?2/29/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))/(?:0?[1-9]|1\d|2[0-8])/(?:(?:1[6-9]|[2-9]\d)\d{2}))$)$
These allow but do not require a leading zero in single-digit months/days. If you don't want that, replace all instances of 0? with 0.
You could use a CustomValidator and have the client-side validation be simple and on the server-side use a DateTime.TryParse to get a definitive validation. Although I suspect you don't need your code to work all the way to the year 9999 (no, I couldn't immediately see if the supplied regexes work that far into the future).
from Microsoft DN but modified to work with years both 20xx and 19xx to used as DOB
^(((((0[1-9])|(1\d)|(2[0-8]))/((0[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0[1,3-9])|(1[0-2])))))/((((20[0-9][0-9]))|(29-02-20(([02468][048])|([13579][26]))))|(((19[0-9][0-9]))|(29-02-19(([02468][048])|([13579][26]))))))$
for dd/MM/yyyy formate
(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$

Regular Expression for TimeSpan in format "hh.mm"

I want to create RegularExpressionValidator for validation TextBox format hh.mm.
This expression works:
^([0-9]|0[0-9]|1[0-9]|2[0-3]).[0-5][0-9]$
But if I insert 5454 in the TextBox it also passes, but it shouldn't.
. is a meta character in regular expressions that matches any character. If you want to match literally just a period, then you need to escape it:
^([0-9]|0[0-9]|1[0-9]|2[0-3])\.[0-5][0-9]$
you forgot to escape .
try
^([0-9]|0[0-9]|1[0-9]|2[0-3])\.[0-5][0-9]$

Regular expression to allow the format as YYMMDD

I have a textbox called period which should allow the user only to enter the string as YYMMDD format. YY can be numbers from 0-99, MM from 1-12 and DD from 01-04.
I want to use regular expression to get this done. Please help me with the expression to achieve this.
Try this "^[0-9][0-9][0-1][1-2][0][1-4]$" the error in your expression is that it will accept: 991214 which is incorrect.
\d\d(?:0[1-9]|1[012])(?:0[1-4])
matches 110701
does not match 110705

Resources