Thursday, November 13, 2008

JavaScript: Function To Check Whether provided string contains some wildcard character

The following function returns true if the string value contains the specific wild-card character.

Parameters:

1- fieldValue -- String

It is a string that needs to be checked whether it contains some special/wildcard characters

2- wildChar -- String/ Single Char

It is a character that you want to search whether it is present in the string passed as first parameter of this function.


function containsWildCard(fieldValue, wildChar)
{
// var fieldValue = window.document.getElementById("fieldID").value;
if (fieldValue.split(wildChar).length > 1)
{
alert ("WildCard!");
return false;
}
else
{
alert ("No - WildCard!");
return true;
}

}

No comments: