String.startsWith Function
Determines whether the start of a String object matches a specified string.
var hasPrefix = myString.startsWith(prefix);
Arguments
- prefix
The string to match with the start of the String object.
Return Value
true if the start of the String object matches prefix; otherwise, false.
Remarks
Use the startsWith function to determine whether the start of a String object matches a specified string. The startsWith function is case sensitive.
Example
The following example shows how to use the startsWith function to determine whether the start of a string matches a specified string. The code excludes non-white-space characters at the start of the string from the validation by invoking the String.trimStart function. Next it calls the String.toLowerCase function so that case sensitivity is also excluded from the validation. Finally, it calls the startsWith function invoked to test the start of the string for a match.