Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent muuuultiple characters 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
0
0
GB
Is it possible to have a textbox into which the user is blocked from entering multiple (more than 3) consecutive identical characters, rather than validating the textbox for the problem when the user tries to submit?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Hi

As it is currently defined, neither the [tt]pattern[/tt] attribute of HTML5's [tt]input[/tt] tag will be enough for that. Maybe in HTML6...

In meantime you will have to validate it yourself. Maybe [tt]onkeyup[/tt] too [sup](*)[/sup], so the visitor gets notified soon about the error.

[small](*) Note that I wrote too. Keep also an [tt]onsubmit[/tt] validation, as pasting with mouse or autocompleting with browser extension/feature will not trigger [tt]onkeyup[/tt].[/small]


Feherke.
 
If you are wanting to stop users from typing certain stuff. You can create and array of all the stuff you don't want. Then create an eventHandler - onkeyup=checkValue() to the textbox.

In the function checkValue(). Get the length of the array and create a for loop and search() for each one. If found replace(array, "").

I hope this helped

tecmeister
 
Hi

Andy said:
blocked from entering multiple (more than 3) consecutive identical characters
tecmeister said:
You can create and array of all the stuff you don't want.
tecmeister, are you serious ? An array of all characters' 4 letter long strings would be horrible.

Regular expressions are good for finding our whether the string contains consecutive characters :
Code:
[blue]>>> 'baaaaad ideeea !!!!'.match(/(.)\1{3,}/g)[/blue]
[b][[/b] [red]"aaaaa"[/red], [red]"!!!!"[/red] [b]][/b]


Feherke.
 
Write a routine that would compare the decimal value of the current character and the decimal value of the previous 2 characters. If all three are the same then you know that three consecutive characters were entered.

Remember if you are on either the first or second character of the string, do not do the compare.
 
Hi

howmnsk said:
compare the decimal value of the current character and the decimal value of the previous 2 characters
Why to compare decimal values and not characters ?


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top