Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2007, 03:29 PM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default textbox validation please help urgent

i have a textbox in windows form. i need to validate it for integer values. i have tried using the regular expressions as follow.

Regex userNameMatch= new Regex("[0-9]*");

if(!userNameMatch.IsMatch(txtUserName.Text))
       {
        ..........
       }


i am trying to accomplish that if the user is not entering any value , including symbols such as " !@#$%^&*()" other than a number it should throw a message.

it would be great if any body could please help me out in this.

Regards
AKSSMV
 
Old June 11th, 2007, 01:45 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

[0-9]* matches zero or more digits, if you want to exclude empty content you can use [0-9]+ which is one or more digits. You can use \d instead of [0-9] if you want to widen the scope to UNICODE digits.

--

Joe (Microsoft MVP - XML)
 
Old June 11th, 2007, 07:40 AM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you, i will try it out

Quote:
quote:Originally posted by joefawcett
 [0-9]* matches zero or more digits, if you want to exclude empty content you can use [0-9]+ which is one or more digits. You can use \d instead of [0-9] if you want to widen the scope to UNICODE digits.

--

Joe (Microsoft MVP - XML)
 
Old June 11th, 2007, 10:45 AM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Everything is working except the empty content i tried [0-9]+ in the Regex constructor but it's not working

i tried inputting "3333@@@" for example.

am i doing any mistake in coding...

please help.....

 
Old June 11th, 2007, 11:09 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, I think you need to make sure that the whole string is parsed:
Code:
^\d+$
^ means "begins with" and $ means "ends with".

--

Joe (Microsoft MVP - XML)
 
Old June 11th, 2007, 11:19 AM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks a lot, it's working now.


Quote:
quote:Originally posted by joefawcett
 Sorry, I think you need to make sure that the whole string is parsed:
Code:
^\d+$


^ means "begins with" and $ means "ends with".

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox validation rhd110 .NET Framework 2.0 1 March 28th, 2007 02:49 PM
textbox validation in c# dhol C# 3 July 22nd, 2005 05:57 AM
TextBox Validation Brettvan1 VB.NET 2002/2003 Basics 1 June 23rd, 2005 08:58 AM
Textbox Validation phudong3da Dreamweaver (all versions) 2 May 9th, 2005 02:47 PM
validation on textbox noor ASP.NET 1.0 and 1.1 Basics 2 May 4th, 2005 02:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.