Thursday 6 July 2017

String to Validate only Numbers [Regular Expression is AX ]

Following is an Example of Regular Expressions :

Job-1:

static void TextBuffer_regularExpression(Args _args)
{
    TextBuffer txt = new TextBuffer();
    str msg = "98797897";
   
    txt.setText(msg);
    txt.regularExpressions(true);   // activate regular expr in search

     // Regular expression to validate only digits
     if (txt.find("^[0-9]+$"))
    {
        info("string contains only numbers");
    }
}

Job-2:

static void TextBuffer_regularExpression(Args _args)
 {
    TextBuffer txt = new TextBuffer();
    str msg = "R12345678";

    msg = substr(msg, 2,9);
    txt.setText(msg);
    txt.regularExpressions(true);   // activate regular expr in search

    // Regular expression to validate only digits
    if (txt.find("^[0-9]+$"))
    {
        info("string contains only numbers");
    }
    else
    {
        info("string contains not only numbers");
    }
 }

No comments:

Post a Comment