Textbox in jsp that allows only text numbers and comma.
this is to seperate userids.
each userid has to be 8 chars in length and i need to enter multiple userids in the textbox.
eg:
correct format is below
asakthi1,psubhadr,tpradee4
it should not end like(with a comma at the end.)(incorrect format)
asakthi1,psubhadr,tpradee4,
this i need to do using javascript.(No Jquery please.)
am scratching my head on this..Any help would be appreciated.
You could attach an
onchangeevent handler to the<input type="text">that will perform the validation using a regular expression like, for instance, this one:^(([A-Za-z0-9]{8}),)*[A-Za-z0-9]{8}$.If a username is a combination of 8 letters or numbers, this expression would accept any number of usernames followed by comma, and at least one final username without a comma. Notice the
{8}element forces a match of exactly 8 characters.If validation fails, it’s up to you how to show it to the user. This example will be showing an alert and clearing the input.
Here is a sample JSFiddle to see the expression at work.