Validate date in edittext box

后端 未结 2 936
广开言路
广开言路 2021-01-16 13:37

I am using the following code to validate date entered in edittextbox.however in xml file I had given its input type date.

int i = validate(registerdate);
         


        
2条回答
  •  甜味超标
    2021-01-16 14:06

    Java will treat \ inside a string as starting an escape sequence. Make sure you use \ instead (so that you get an actual \ character in the string) and you should be ok.

    Quick Update: As Etienne points out, if you actually want a \ in the RegEx itself, you'll need to use \\, since that will produce \ in the string, which will produce \ in the RegEx.

    Your regex after correction:

    String regEx ="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d{2}$";
    

提交回复
热议问题