Validation for Text Box to prevent commas and periods.

I have a webform that has several text boxes.  When users enter information, such as their first name, middle name, and last name into the textboxes I need to prevent any periods or commas from being passed through to my SQL DB with the name.  For instance:

John D Smith will work fine.  

But, John D. Smith will not work.

Is there some way to validate that text entered either by a validator in Visual Studio, or some way that I could code that into my save button?
Who is Participating?
should be ^[\w\d]+$

the [] - brackets contain what to look for and the \w matches any alphanumeric and the \d matches any decimal digit. The \s matches whitespace characters

on second thought you might be able to get away with just:

Use a RegularExpressionValidator with this regular expression:


This will only allow letters, numbers, and spaces (no punctuation).
using javascript you could create a regular expression that will only allow the characters you want entered into the text box ... or you could just strip them out on the server side ... or using the Regular Expression Validator control ... that should work.

What characters do you want to allow ... only letters and spaces?
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
You can also try the nice Vb.Net component ErrorProvider (System.Forms.Component.ErrorProvider) It's very nice and informs the user when the error is done not at the end of the typing.

officerhandsomeAuthor Commented:

How about if I also didn't want spaces?  Then what would that validation statement look like?
officerhandsomeAuthor Commented:
Perfect, Thanks.  Can anyone recommend a good source to learn how to write these validation expressions?
Google: Regular Expressions

This looks like a decent place to start:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.