我有一些這樣的輸入
<input type="text" formControl="presentEstimatedValue"
class="form-control">
并在現場進行驗證,例如:
presentEstimatedValue: [null, [[Validators.required,
Validators.pattern(/^\d{1,8}(?:\.\d )?$/)]]
我希望允許 0 到 99999999 之間的數字,有或沒有千位分隔符,使用點作為分隔符。也就是說,最小的數字是 0,最大的數字是 99999999 或 99.999.999,后者帶有點千位分隔符。我需要支持這兩種可能的格式。
我已經嘗試過 Validation.min 和 max 但這僅適用于型別號:(
uj5u.com熱心網友回復:
您可以使用以下正則運算式模式:
^(?:(?=.{1,10}$)\d{1,3}(?:\.\d{3})*|\d{1,8})$
以下是正則運算式模式的解釋:
^ from the start of the number
(?:
(?=.{1,10}$) assert that total length is 0 to 10
\d{1,3} match 1 to 3 digits
(?:\.\d{3})* then match dot-3 digit groups, zero or more times
| OR
\d{1,8} match a pure number of 1 to 8 digits
)
$ end of the number
這是一個演示。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420668.html
標籤:
