Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validation for Text Box to prevent commas and periods.

Posted on 2004-11-01
7
Medium Priority
?
693 Views
Last Modified: 2011-04-14
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?
0
Comment
Question by:officerhandsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Assisted Solution

by:Timbo87
Timbo87 earned 500 total points
ID: 12467273
Use a RegularExpressionValidator with this regular expression:

^[\w\d\s]+$

This will only allow letters, numbers, and spaces (no punctuation).
0
 
LVL 14

Expert Comment

by:dfu23
ID: 12467295
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?
0
 
LVL 5

Expert Comment

by:Ignacio Soler Garcia
ID: 12480959
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.

SoMoS
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:officerhandsome
ID: 12486716
Timbo87,

How about if I also didn't want spaces?  Then what would that validation statement look like?
0
 
LVL 14

Accepted Solution

by:
dfu23 earned 500 total points
ID: 12486829
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:

^[\w]+$
0
 

Author Comment

by:officerhandsome
ID: 12486943
Perfect, Thanks.  Can anyone recommend a good source to learn how to write these validation expressions?
0
 
LVL 14

Expert Comment

by:dfu23
ID: 12487071
Google: Regular Expressions

http://www.google.com/search?q=regular+expressions

This looks like a decent place to start: http://etext.lib.virginia.edu/helpsheets/regex.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question