wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Restricting 2 adjacent commas in text field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Restricting 2 adjacent commas in text field" Watch "Restricting 2 adjacent commas in text field" New topic

Restricting 2 adjacent commas in text field

ashu srivastava

Joined: Jun 25, 2011
Posts: 6
Hi All,
I have a requirement where user can put more than 1 values separated by commas. I am restricting all the special characters using javascript except comma, so user is able to enter comma in the field.

Now, I want to restrict user from entering more than 1 comma continuously,
Could anyone please suggest me how I should create javascript function to achieve this.

Thanks in advance.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

when user enter character, just check the previous character. if it is comma show error
[another way is]
just take the value which is *entered* by user then split then just any value is "" or " " if it is then show error
I agree. Here's the link: http://aspose.com/file-tools
subject: Restricting 2 adjacent commas in text field
Similar Threads
Newbie to JavaScript
How to put javascript validation to avoid special characters except comma ?
RegExpr to Add Comma and Decimal Points
String --> split/regex question
How to split String array which has comma seperated values