简体   繁体   English

十进制值的正则表达式限制为16位

[英]regex for decimal value restrict 16 digit

I want a regex expression to restrict input decimal value at max. 我想要一个正则表达式来限制最大输入十进制值。 16 digits or 15 digits and one character (including decimal point) 16位或15位数字和一个字符(包括小数点)

I found below Regex it is working find in C# code but when i am using it in TextEdit xaml as mask. 我在正则表达式下面发现它可以在C#代码中找到,但是当我在TextEdit xaml中将其用作遮罩时。 (DevExpress) throwing exception syntax error : (DevExpress)抛出异常syntax error

例外

Mask: 面具:

^(?:(?=.{0,16}$)\d*\.\d+|\d{0,16})[kKmMbBtT]?$

TextEdit Xaml: TextEdit Xaml:

<dxe:TextEdit HorizontalAlignment="Left" MaskType="RegEx"
     Mask="(?:(?=.{0,16}$)[0-9]*([.]?[0-9]+)|[0-9]{0,16})[kKmMbBtT]?"
     VerticalAlignment="Top" Width="150"
     EditValue="{Binding DecValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
     Margin="10,33,0,0"/>

Purpose I want to achieve from it: 目的我想从中实现:

  • User can enter at 16 digits decimal value (including decimal point) or 用户可以输入16位十进制值(包括小数点)或
  • user can enter 15 digit and one character (including decimal point) 用户可以输入15位数字和一个字符(包括小数点)
  • He can enter only decimal point one time 他一次只能输入小数点
  • Total length of input string must not more than 16 characters. 输入字符串的总长度不能超过16个字符。

According to documentation : 根据文件

Extended Regular Expressions provide almost unlimited flexibility to create input masks. 扩展正则表达式为创建输入掩码提供了几乎无限的灵活性。 The syntax used by masks in this mode is similar to the syntax defined by the POSIX ERE specification. 在此模式下,掩码使用的语法类似于POSIX ERE规范定义的语法。 Back referencing is not supported. 不支持反向引用。

So, you cannot use grouping constructs such (?: subexpression ) or (?= subexpression ) etc. You can use some weird mask like this: 因此,您不能使用(?: subexpression )(?= subexpression )等分组构造。您可以使用一些奇怪的掩码,例如:

\d{0,16}|\d{14}\R.\d{1}|\d{13}\R.\d{1,2}|\d{12}\R.\d{1,3}|\d{11}\R.\d{1,4}|\d{10}\R.\d{1,5}|\d{9}\R.\d{1,6}|\d{8}\R.\d{1,7}|\d{7}\R.\d{1,8}|\d{6}\R.\d{1,9}|\d{5}\R.\d{1,10}|\d{4}\R.\d{1,11}|\d{3}\R.\d{1,12}|\d{2}\R.\d{1,13}|\d{1}\R.\d{1,14}|\R.\d{1,15}

And in your XAML: 在您的XAML中:

<dxe:TextEdit HorizontalAlignment="Left" MaskType="RegEx"
     Mask="\d{0,16}|\d{14}\R.\d{1}|\d{13}\R.\d{1,2}|\d{12}\R.\d{1,3}|\d{11}\R.\d{1,4}|\d{10}\R.\d{1,5}|\d{9}\R.\d{1,6}|\d{8}\R.\d{1,7}|\d{7}\R.\d{1,8}|\d{6}\R.\d{1,9}|\d{5}\R.\d{1,10}|\d{4}\R.\d{1,11}|\d{3}\R.\d{1,12}|\d{2}\R.\d{1,13}|\d{1}\R.\d{1,14}|\R.\d{1,15}"
     VerticalAlignment="Top" Width="150"
     EditValue="{Binding DecValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
     Margin="10,33,0,0"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM