Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 检查字符串是否包含数字或是数字-Thymeleaf_Regex_String_Thymeleaf_Isnumeric - Fatal编程技术网

Regex 检查字符串是否包含数字或是数字-Thymeleaf

Regex 检查字符串是否包含数字或是数字-Thymeleaf,regex,string,thymeleaf,isnumeric,Regex,String,Thymeleaf,Isnumeric,是否有方法检查字符串是否为数字。 {#strings.isNumeric(dataField)}不起作用 如何检查字符串是否包含数字(以及特定的位数)-是否有可以使用的正则表达式,或者是否有可以调用的内置函数 要避免以下情况: {#string.contains('1') or #string.contains('2')} 尝试匹配(): 这与长度为3到8位(包括)的字符串相匹配。您可以将这些值更改为适合您的任何值 您还可以使用开放式长度范围:[0-9]{3,}表示“至少3位”如果您的路径中有

是否有方法检查字符串是否为数字。
{#strings.isNumeric(dataField)}
不起作用

如何检查字符串是否包含数字(以及特定的位数)-是否有可以使用的正则表达式,或者是否有可以调用的内置函数

要避免以下情况:

{#string.contains('1') or #string.contains('2')}
尝试
匹配()

这与长度为3到8位(包括)的字符串相匹配。您可以将这些值更改为适合您的任何值


您还可以使用开放式长度范围:
[0-9]{3,}
表示“至少3位”

如果您的路径中有库
org.apache.commons.lang3
,则可以将其用作下一个路径

${T(org.apache.commons.lang3.StringUtils).isNumeric(dataField)}
因此,如果您想使用if块,它将是:

<th:block th:if="${T(org.apache.commons.lang3.StringUtils).isNumeric(dataField)}">
   <p>Is numeric!</p>
</th:block/>
然后将其用于下一个表达式:

${T(your.package.Utils).isNumeric(dataField)}

出于某种原因,这不起作用testStringResult=${#strings.matches(testString,[0-9]')}错误:org.springframework.expression.spel.SpelEvaluationException:EL1004E:(位置9):方法调用:方法匹配(java.lang.String,java.lang.String)在org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:273)@loser的org.thymeleaf.expression.Strings类型中找不到。我不熟悉thymeleaf,但请尝试我编辑的代码
package your.package;

public class Utils {
     public static boolean isNumeric(String data){
           //impl
           return true;
     }
}
${T(your.package.Utils).isNumeric(dataField)}