Search StringVar for Regular Expression Method

The Search StringVar for Regular Expression method searches a string for a regular expression. It returns one of the following:

  • If it finds the regular expression, then it returns the position of this regular expression.

  • If it does not find the regular expression, then it returns negative 1.

You can write code that runs this method in server script or browser script.

This method uses the same argument as the Get Regular Expression From StringVar method. For more information, see Get Regular Expression From String Var Method.

Format

stringVar.search(regexp)

The following example uses the Search StringVar for Regular Expression method:

function Test(sValue)
{
   //Validate for 5 digit numbers
     var sCheck = /^\d{5}$/;  //regular expression defining a 5 digit number
     if(sValue.search(sCheck)==0)
  {
        return("Valid");
     }
     else
     {
        return("Invalid");
  }
}