Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ JAVA and C# _ Testing Whether A String Matches A Given Format.

Posted by: Kamulegeya Feb 22 2014, 05:23 AM

Hello community.
How can i test in code whether values entered in Text field match the format "yyyy-mm-dd"?
Ronald

Posted by: Kamulegeya Feb 22 2014, 09:01 AM

Found this

CODE
String pattern="^(19|20)\\d\\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
String tomatch=readingDate.getText().toString();
                        isvalid=tomatch.matches(pattern);

and works great....regex looks like Arabic to me!

Posted by: orange999 Feb 22 2014, 09:24 AM

regex is great for pattern testing, matching and/or extraction.
I'm not a java C# programmer, but have used it with Access and VBA.
There are many articles/tutorials/examples on the internet.