static void THK_isNumericForRegularExpression(Args _args)
{
TextBuffer txt = new TextBuffer();
str msg = "9879q7897";
;
txt.setText(msg);
txt.regularExpressions(true); // activate regular expr in search
setprefix(msg);
// Regular expression to validate only digits
if (txt.find("^[0-9]+$"))
{
info("Yes,string contains only numbers");
}
else
checkFailed("No");
}
2) build - in methodstatic void THK_isNumeric(Args _args)
{
str st = "1234we7878899";
boolean isNumeric(str StrNumVar)
{
boolean ret = true;
int m,n;
str s = strkeep(StrNumVar,"1234567890");
;
m = strlen(StrNumVar);
n = strlen(strkeep(StrNumVar,"1234567890"));
ret = m == n;
return ret;
}
boolean THK_validNumbers(str _text)
{
int counter, textLen = strlen(_text);
Phone validNumbers = '0123456789';
;
for(counter = 1; counter <= textLen; counter ++)
{
if(!strfind(substr(_text,counter,1), validNumbers, 1, 10))
{
return false;
}
}
return true;
}
;
info(queryValue(isNumeric(st)));
info(queryValue( THK_validNumbers (st)));
}
没有评论:
发表评论