So I’m trying to validate my text field in javascript so that it would only have one hyphen.
I managed to make it so they cannot be side by side but that’s inefficient since the user can still input the hyphen else where.
What I tried to do is this:
if (surname.indexOf("-") > 1)
{
err += "You cannot use more than one hyphen (-) for Client Surname";
}
But that did not work. I also tried >=2 still no good.
What would you suggest looking into or trying?
Thanks.
Basically, take the length of the original string and compare it against the length of the string with all the hyphens removed. If the difference is 2 or more, there’s more than 1 hypen.