如何将此Java表达式转换为Java脚本表达式:
if(this.myStringValue != null &&
!this.myStringValue.equals("") &&
!this.myStringValue.matches("[\\d]*")){
// do something
}
' myStringValue'是Java中的String。
JavaScript中的逻辑是什么?非常感谢帮助我!
答案 0 :(得分:0)
它可以转化为:
if (this.myStringValue != null && this.myStringValue != "" && !/\d*/.test(this.myStringValue) ){
// do something
}
无论如何,这些测试毫无意义。 [\\d]*
总是如此。我们可以尝试:
if ( this.myStringValue && !/\d+/.test(this.myStringValue) ) {}
答案 1 :(得分:0)
你可以使用它,
> var s = ''
undefined
> s != null && !s.match(/^\d*$/)
false
> var s = 'bar'
undefined
> s != null && !s.match(/^\d*$/)
true
> var s = '23'
undefined
> s != null && !s.match(/^\d*$/)
false