How to check a string contains only digits and one occurrence of a decimal point?

后端 未结 8 1527
一向
一向 2021-02-15 14:37

My idea is something like this but I dont know the correct code

if (mystring.matches(\"[0-9.]+\")){
  //do something here
}else{
  //do something here
}
<         


        
8条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 14:56

    I create myself to solve exactly question's problem. I'll share you guys the regex:

    ^(\d)*(\.)?([0-9]{1})?$

    Take a look at this Online Regex to see work properly

    Refer documentation if you wish continue to custom the regex

    Documentation

提交回复
热议问题