473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression Validator with MultiLine TextBox

7 New Member
I have created a regular expression to validate dates in MM/DD/YYYY, MM/YYYY, and YYYY. "((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d " . How can I make this expression work with a multi-line textbox, so that a user would be able to enter multiple dates (each on a new line) and still be validated by my expression.

Example: 3 dates entered into textbox, all be validated by expression.
Multi-Line TextBox:
01/01/2008
01/2007
2006
Jun 3 '08 #1
7 2522
Sick0Fant
121 New Member
I have created a regular expression to validate dates in MM/DD/YYYY, MM/YYYY, and YYYY. "((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d " . How can I make this expression work with a multi-line textbox, so that a user would be able to enter multiple dates (each on a new line) and still be validated by my expression.

Example: 3 dates entered into textbox, all be validated by expression.
Multi-Line TextBox:
01/01/2008
01/2007
2006
Well, you can split the input by newline, then use a for each loop to validate each one. Although, I'd wonder if you shouldn't just use a date-time picker to populate a listbox-- then you wouldn't need to validate it yourself because the date-time picker returns a date data type.
Jun 3 '08 #2
wagswvu
7 New Member
I'm using a RegularExpressi onValidator.

here is sample code

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)   
  2.     {   
  3.  
  4.         TextBox textBox1 = new TextBox();   
  5.         textBox1.ID = "textBox1";
  6.         textBox1.TextMode = TextBoxMode.MultiLine;
  7.         textBox1.Rows = 10; 
  8.         form1.Controls.Add(textBox1);       
  9.  
  10.         Button SubmitButton = new Button();   
  11.         SubmitButton.ID = "SubmitButton";   
  12.         SubmitButton.Text = "Submit";   
  13.         SubmitButton.Click += new EventHandler(SubmitButton_Click);   
  14.         form1.Controls.Add(SubmitButton);   
  15.  
  16.         RegularExpressionValidator datevalidator = new RegularExpressionValidator();   
  17.         datevalidator.ControlToValidate = "textBox1";   
  18.         datevalidator.Text = "Enter Correct Date";   
  19.         datevalidator.ValidationExpression = @"((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d";    
  20.         form1.Controls.Add(datevalidator);   
  21.  
  22.     }   
  23.  
  24.     private void SubmitButton_Click(object sender, System.EventArgs e)   
  25.     {   
  26.         //Get output from textbox   
  27.         //Value output will look like : "value1\r\nvalue2\r\nvalue3"   
  28.     }  
Jun 3 '08 #3
Sick0Fant
121 New Member
I'm using a RegularExpressi onValidator.

here is sample code

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)   
  2.     {   
  3.  
  4.         TextBox textBox1 = new TextBox();   
  5.         textBox1.ID = "textBox1";
  6.         textBox1.TextMode = TextBoxMode.MultiLine;
  7.         textBox1.Rows = 10; 
  8.         form1.Controls.Add(textBox1);       
  9.  
  10.         Button SubmitButton = new Button();   
  11.         SubmitButton.ID = "SubmitButton";   
  12.         SubmitButton.Text = "Submit";   
  13.         SubmitButton.Click += new EventHandler(SubmitButton_Click);   
  14.         form1.Controls.Add(SubmitButton);   
  15.  
  16.         RegularExpressionValidator datevalidator = new RegularExpressionValidator();   
  17.         datevalidator.ControlToValidate = "textBox1";   
  18.         datevalidator.Text = "Enter Correct Date";   
  19.         datevalidator.ValidationExpression = @"((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d";    
  20.         form1.Controls.Add(datevalidator);   
  21.  
  22.     }   
  23.  
  24.     private void SubmitButton_Click(object sender, System.EventArgs e)   
  25.     {   
  26.         //Get output from textbox   
  27.         //Value output will look like : "value1\r\nvalue2\r\nvalue3"   
  28.     }  
Is this for an assignment? If so, do it to your specs. I'm just saying that you never want to reinvent the wheel. The date-time picker gives you a valid date, so you wouldn't have to validate it yourself. If the idea is that the user will be entering so many dates that the dtp would be cumbersome, you may want to look ate date.TryParse() .

BTW, why create the controls at run time? Especially if you're doing this in the load event, you might as well optimize performance and create the controls at design time.

EDIT:

I forgot that what is being inputed might not be only the year. I'm not sure that TryParse would be successful with such an input. So, like I said before, split the text of the text box by the newline character, trim any spaces, then use a foreach to validate each line using your regex.
Jun 3 '08 #4
wagswvu
7 New Member
Is this for an assignment? If so, do it to your specs. I'm just saying that you never want to reinvent the wheel. The date-time picker gives you a valid date, so you wouldn't have to validate it yourself.

BTW, why create the controls at run time? Especially if you're doing this in the load event, you might as well optimize performance and create the controls at design time.
No, I'm working a proof of concept for a business project. The reason I can't use the datetime picker is because the data that will be inputed in either MM/DD/YY, MM/YYYY, or YYYY.(this is document metadata, so it's need to be inputed as is) As for the code it's just a crappy concept I made to mess with the expression. What I am trying to figure out is how to get the RegularExpressi onValidator to validate my input when the user enters multiple dates in a multi-line textbox.....
Jun 3 '08 #5
Sick0Fant
121 New Member
No, I'm working a proof of concept for a business project. The reason I can't use the datetime picker is because the data that will be inputed in either MM/DD/YY, MM/YYYY, or YYYY.(this is document metadata, so it's need to be inputed as is) As for the code it's just a crappy concept I made to mess with the expression. What I am trying to figure out is how to get the RegularExpressi onValidator to validate my input when the user enters multiple dates in a multi-line textbox.....
I know nothing of the RegularExpressi onValidator.

I've only used the .NET RegEx object. To validate if a string is accepted by your regular expression, first declare a RegEx object:

RegEx MyRegEx = new RegEx(MyStringR epresentationOf MyRegularExpres sion);

Then, too see if a string is validated:

MyRegEx.IsMatch (StringToBeVali dated);
Jun 3 '08 #6
wagswvu
7 New Member
I know nothing of the RegularExpressi onValidator.

I've only used the .NET RegEx object. To validate if a string is accepted by your regular expression, first declare a RegEx object:

RegEx MyRegEx = new RegEx(MyStringR epresentationOf MyRegularExpres sion);

Then, too see if a string is validated:

MyRegEx.IsMatch (StringToBeVali dated);
somebody help me on another forum.. FYI, here is the answer:

(((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d (\s+)?)+
Jun 4 '08 #7
Sick0Fant
121 New Member
somebody help me on another forum.. FYI, here is the answer:

(((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d (\s+)?)+
Next time, say that you need help with the regular expression itself. I assumed that you had a valid re and merely wanted to know how to validate a string with it. The unix forum is a better place for this question.
Jun 4 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2211
by: Mark | last post by:
To validate the length of a multiline textbox, I'm told that I have to use a regular expression validator. The regular expression below limits it to 25 characters in length, but if the user enters a hard return, it bombs regardless of length. How do you allow hard returns in the following regular expression? Thanks in advance! ^.{0,25}$ ...
2
2937
by: VSK | last post by:
Hi all, I have a .ascx file with dropdownbox (SSN, EmpName) textbox submit button regular expression validator( controltovalidate is the above textbox) Now i want to change the Regular Expression of the validator based on the
2
5568
by: S.Kartikeyan | last post by:
I have the following problem. I am using the follwing Regular Expression validator(REV) with validator expressions ^{1,2}$ ^{3,20}$ The idea of the first exp is 1 or 2 digits the idea of second expression is username between 3 and 20 chars When the user enters characters other than the specified REVs are working. But if the user leaves...
2
9856
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something, such as change the border color of the textbox to red? That would look quite nice: if the expression fails, the red validator text is shown, plus...
7
25368
by: Chris Kennedy | last post by:
Does anyone know a regular expression that will validate the file extension but also allow multiple file extensions if necessary. It also needs to be case insensitive. Basically, what I want is to validate a file input box to check if the extension is the correct type, i.e. .doc for a Word Document etc. Also I would like to check multiple file...
5
1095
by: Kerry | last post by:
Please help. I need a regular expression that parses a stream of up to 450 characters into 15 separate strings of up to 30 characters each. The regex must break at newlines. Ideally, the regex will "word wrap" that is, not break in the middle of words. I have the following: (?m:(?:(.)?){1,30}\s\n?){1,15}? This works well as long as...
6
7955
by: David | last post by:
I'm having trouble getting the regular expression validator to work with a text box. In this simple example I only want lower case letters to be allowed. So I tried the following and it doesn't work, would somebody be so kind as to tell me why. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator...
2
1823
by: Joey | last post by:
Hello guys, I'm trying to learn about regular expressions. I need to be able to use an RE that can evaluate for STRINGS (or specific sequences of characters), not just occurances of characters. Everything I have read thus far involves checking only for the presence or absence of characters. Can anyone provide an RE that will correctly...
0
1528
by: durga2005 | last post by:
hi i just added one textbox and regular expression validator in the form and set the properties for regular expression validator control. then i placed these two controls inside update panel . when i execute this, the validation was not working before placing in update panel validation was working
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.