我有一个输入字段,其中填充了JSON对象数据。
dimension: {
length: 10.00,
width: 20.00,
height: 30.00,
}
输入看起来像这样:
<input matInput [placeholder]="Dimension (LxHxW)" formControlName="dimensions"
name="dimensions" mask="00.0x00.0x00.0" [specialCharacters]="['x', '.']"
[clearIfNotMatch]="true" [showMaskTyped]="true"
/>
其中维度在typescript代码中构建为:
let dimensions = null;
if (dimensionObject) {
dimensions = '' + dimensionObject.length + 'x' + dimensionObject.width + 'x'
+ dimensionObject.height;
}
目标是正确地映射掩模上的数据并获得与x之间连接的长度,宽度和高度 - >获得灵活的掩模。
维度值长度不同时会出现问题:
例如如果尺寸为2.3 x 12.3 x 42.2而不是2.3 x 12.3 x 42.2,它将显示23.1 x 23.4 x 22.(x移位)。
你们可以发现任何解决方案?
我想你必须使用模式
以下示例取自this article on CSS-tricks, by Chris Coyier但created by Estelle Weyl,展示了如何使用A1A 1A1表格处理加拿大邮政编码:
<div> <label for="czc">Canadian Zip Code</label> <input id="czc" placeholder="XXX XXX" pattern="\w\d\w \d\w\d" class="masked" data-charset="_X_ X_X" id="zipca" type="text" name="zipcodeca" title="6-character alphanumeric zip code in the format of A1A 1A1" /> </div>
在您的情况下,您应该只更改模式正则表达式。