Axapta 验证类
我在 AX2009 中编写了一种处理正则表达式验证的方法。问题是,无论表达式或输入字符串是什么,它总是返回 false。不返回任何错误,只是“错误” 介意看一下吗?我可能错过了一些简单的事情。
这篇文章已更新,包含更正的方法,没有错误,因此您可以剪切并粘贴代码以在您的项目中使用。符合 BP 标准并随时可用。 - 尽情享受
static boolean validateMe(str regexFilter, str _testString)
{
System.Text.RegularExpressions.Match regExMatch;
boolean retVal;
str regExpression;
;
//See if any of the static expressions were selected
switch (regexFilter)
{
case 'integer' :
regExpression = '^\\d+$';
break;
case 'rgbcolor' :
regExpression = '^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\,([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\,([01]?\\d\\d?|2[0-4]\\d|25[0-5])$';
break;
case 'number' :
regExpression = '^(\\d+\\.?\\d*|\\d*\\.?\\d+)$';
break;
case 'email' :
regExpression = '^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$';
break;
case 'phone' :
regExpression = '^(\\()?(\\d{3})(\\)|-)?([0-9]{3})(-)?([0-9]{4}|[0-9]{4})$';
break;
case 'nopunctationphone' :
regExpression = '^\\d{10}$';
break;
default :
//No static expression matched, use the passed-in value
regExpression = regexFilter;
}
//see if the string matches
if (_testString != '')
{
//see if string matches expression; validation is good
regExMatch = System.Text.RegularExpressions.Regex::Match(_testString, regExpression);
retVal = regExMatch.get_Success();
}
else
{
//string does NOT match expression; validation fails
retVal = false;
}
return retVal;
}
I've written a method to handle regex validation in AX2009. Problem is that it always returns false, no matter what the expression or input string. Returns no errors, just 'false' Mind taking a look? I'm probably missing something simple.
This post has been updated to included the corrected method, without the error, so you can cut and paste the code for use in your project. BP compliant and ready for use. - Enjoy
static boolean validateMe(str regexFilter, str _testString)
{
System.Text.RegularExpressions.Match regExMatch;
boolean retVal;
str regExpression;
;
//See if any of the static expressions were selected
switch (regexFilter)
{
case 'integer' :
regExpression = '^\\d+
;
break;
case 'rgbcolor' :
regExpression = '^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\,([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\,([01]?\\d\\d?|2[0-4]\\d|25[0-5])
;
break;
case 'number' :
regExpression = '^(\\d+\\.?\\d*|\\d*\\.?\\d+)
;
break;
case 'email' :
regExpression = '^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)
;
break;
case 'phone' :
regExpression = '^(\\()?(\\d{3})(\\)|-)?([0-9]{3})(-)?([0-9]{4}|[0-9]{4})
;
break;
case 'nopunctationphone' :
regExpression = '^\\d{10}
;
break;
default :
//No static expression matched, use the passed-in value
regExpression = regexFilter;
}
//see if the string matches
if (_testString != '')
{
//see if string matches expression; validation is good
regExMatch = System.Text.RegularExpressions.Regex::Match(_testString, regExpression);
retVal = regExMatch.get_Success();
}
else
{
//string does NOT match expression; validation fails
retVal = false;
}
return retVal;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已经交换了它应该是的变量:
You have swapped the variables it should be:
难道你需要转义字符串内的反斜杠吗?
ETC。
Could it be that you need to escape the backslashes inside strings?
etc.