I want to create a regular expression to check for valid dimension length x breadth x height in javascript.
F开发者_运维知识库or e.g. 90.49 x 34.93 x 40.64
Sample code I intend to use:
var dimensionRegex = 'the regular expression for validation dimension string';
var tempDimension  = 'dimension string input by the user';
if (dimensionRegex.test(tempDimension)) {
    return true;
} else { 
    return false;   
}
Any help would be greatly appreciated.
Why use regexps for that? You could just split('x') the string and then strip leading/trailing space from the array elements. Then you parseInt(elem, 10) the array elements and you have what you need.
However, if you actually want to validate the format:
var dimValid = /^\d+(\.\d+)? x \d+(\.\d+)? x \d+(\.\d+)?$/.test(tempDimension);
This will match number x number x number.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论