views:

625

answers:

3

hi everyone,

I really neeed dd-mon-yy format because my oracle database accepts dates in this format.

Can I validate like that in RegularExpressionValidator like that?

And also, do I have to convert the textbox value to oracle data time format, when using nhibernate?

thanks a lot for help;

+3  A: 

try

Regx.ValidationExpression=@"^(([1-9])|(0[1-9])|(1[0-2]))\-((0[1-9]) |([1-31]))\-((\d{2})|(\d{4}))$";

or

you can try this custom validator instead

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) {

DateTime result;

if (!DateTime.TryParse(args.Value, out result))

{

args.IsValid = false;

return;

} else args.IsValid = true;

}

DaDa
+1  A: 

For two digits for the year try:

^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])-\d\d$

With four digits for the year:

^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])-(19|20)\d\d$

Those expressions mean:

  • 0 or 1 or 2 followed by a number, or 3 plus 0 or 1
  • next a dash
  • For the month it 'tries' all the combinations of JAN, JAn, Jan, jan, etc... for all the twelve months
  • next a dash
  • Finally it expects two digits for 'yyyy' version or 19 or 20 followed by two digits for 'yy' version
victor hugo
+2  A: 

Is it necessary to force the user to enter the data in the format proscribed by the Oracle database? As long as the user enters a valid date, you can parse the input into a DateTime object and then call ToString("dd-MMMM-yy") to produce a representation of the date in the format required by the database. This gives you the freedom to provide more a user-friendly means of collecting input from the user e.g. a date/time picker type control.

pmarflee