Entry
How do I confirm that the first 2 (or other) characters in a string are zeros.
Jan 12th, 2004 15:06
Jean-Bernard Valentaten, Elson Browne,
Using the methods of the String object, this task is accomplished (and
programmed) in no time:
var myString = '';
//do something with myString
...
//check whether the first two chars are zeros
if (myString.substr(0, 2) = '00')
{
//do something
...
}
//check whether the two characters starting at n-th position are zeros
if (myString.substr(n-1, 2) = '00')
{
}
//do something else
...
If you just want to check the position of the two zeros use the method
indexOf() (which will return -1 if '00' is not found):
var myString;
//do something with myString
...
//check whether '00' is contained in myString
if (myString.indexOf('00') != -1)
{
//do something
...
}
HTH,
Jean