last day (22 days later) » 

9:24 AM
1
Q: Date Validation using regex

Trafalgar D LawBelow code is an existing code in my working project and I didn't start it. All I know is that this code is validating a Date if it is valid or invalid format. function isValidDate(div, field) { var reg = /^((0?\d)|(1[012]))\/([012]?\d|30|31)\/\d{1,4}$/; var dateField = $("#" + div + " #...

 
@Igle and Wiktor Thanks. I will read it.
@WiktorStribiżew how can i change the format from / into -?
 
Replace \/ with -
 
@WiktorStribiżew Thanks a lot really appreciate it.
 
To support both - /^((0?\d)|(1[012]))[\/-]([012]?\d|30|31)[\/-]\d{1,4}$/ or /^(?:0?\d|1[012])([\/-])(?:[012]?\d|30|31)\1\d{1,4}$/
 
9:24 AM
Okay I will try it. Thanks
@WiktorStribiżew lastly. How to make MM/dd/yyyy read it as valid?.
 
Sorry, no idea what you mean.I guess you can just parse the input as a Date object and see if the data received is correct. You can grab day, month, year info with capturing groups - /^((0?\d)|(1[012]))[\/-]([012]?\d|30|31)[\/-]\d{1,4}$/ or /^(0?\d|1[012])([\/-])([012]?\d|30|31)\2(\d{1,4})$/ (days - Group 1, months - Group 3 and years - Group 4).
 
I have a default value of MM/dd/yyyy and I use the code but it can't read the MM/dd/yyyy
hello mate.. If I can't reply after 5-10 mins don't leave okay?.
 

  last day (22 days later) »