Following is an Example of Regular Expressions :
public boolean validate()
{
boolean ret;
anytype isValid;
str universalNum = CustTable_HSI_UniversalId.valueStr(); // let say "R12345678"
// or str universalNum = CustTable_HSI_UniversalId.text(); // let say "R12345678"
TextBuffer txt = new TextBuffer();
// ret = super();
isValid = strlen(CustTable_HSI_UniversalId.valueStr());
if (isValid == 9)
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should be upto 9-character");
}
isValid = strFind(CustTable_HSI_UniversalId.valueStr(),'R',1,1);
if (isValid == 1)
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should start wiith 'R' character");
}
universalNum = substr(universalNum, 2,9);
txt.setText(universalNum);
txt.regularExpressions(true); // activate regular expr in search
// Regular expression to validate only digits
if (txt.find("^[0-9]+$"))
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should start wiith 'R' character and contains 0-9 consecutive numbers");
}
ret = super();
return ret;
}
public boolean validate()
{
boolean ret;
anytype isValid;
str universalNum = CustTable_HSI_UniversalId.valueStr(); // let say "R12345678"
// or str universalNum = CustTable_HSI_UniversalId.text(); // let say "R12345678"
TextBuffer txt = new TextBuffer();
// ret = super();
isValid = strlen(CustTable_HSI_UniversalId.valueStr());
if (isValid == 9)
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should be upto 9-character");
}
isValid = strFind(CustTable_HSI_UniversalId.valueStr(),'R',1,1);
if (isValid == 1)
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should start wiith 'R' character");
}
universalNum = substr(universalNum, 2,9);
txt.setText(universalNum);
txt.regularExpressions(true); // activate regular expr in search
// Regular expression to validate only digits
if (txt.find("^[0-9]+$"))
{
ret = true;
}
else
{
ret = false;
throw Global::error("Universal Id should start wiith 'R' character and contains 0-9 consecutive numbers");
}
ret = super();
return ret;
}
No comments:
Post a Comment