?
Solved

Reqular Expression With Carriage Returns

Posted on 2015-01-24
10
Medium Priority
?
86 Views
Last Modified: 2015-01-24
Greetings;

I'm using the follow regular expressions within an ASP.NET environment:
^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,]+$

Open in new window

I need to be able to accept carriage return combinations or characters.

I would like to know how to alter my regular expression to accept carriage returns (Windows, Macintosh, UNIX, etc.)


Much thanks ...
0
Comment
Question by:David Bach
[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
  • 5
  • 5
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568397
Add "\r" to your pattern.

e.g.

^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,\r]+$

Open in new window

0
 

Author Comment

by:David Bach
ID: 40568438
Greetings kaufmed;

Using ASP.NET, adding the \r does not resolve carriage returns.


Thank you for your time though.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568457
\r represents a carriage return. Period. There's no other character to represent such. So, my question to you would be:  Have you inspected the data crossing the wire? Is it really a carriage return?
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:David Bach
ID: 40568512
Greetings kaufmed;

My apologies. I omitted crucial information.

I am using an asp:RegularExpressionValidator, setting the ValidationExpression to the regular expression I mentioned.

Is there a way to set the RegexOptions attribute for this control as well to RegexOptions.Multiline?


Much thanks ...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568533
Multi-line has no bearing on whether or not you can enter a carriage return. Multi-line changes the behavior of ^ and $.

Just to be clear:  Are we talking about carriage returns or newlines?
0
 

Author Comment

by:David Bach
ID: 40568543
Hi Kaufmed;

I am encountering hex ODOA characters in an asp:TextBox with the TextMode="MultiLine" value set.

I hope this helps.

Much thanks ...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568547
0D0A is a carriage return/newline combination, not simply a carriage return. You need to account for both characters:

^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,\r\n]+$

Open in new window

0
 

Author Comment

by:David Bach
ID: 40568571
Hi Kaufmed;

I agree with your assessment, however, without the ability to set regex options for the asp:RegularExpressionValidator I do not see how the regular expression will work even with the \r and \n characters (which I have tried to no avail).

Using RegexBuddy by JustGreat Software, the regular expression only works if the multiline option is set, otherwise there is no match.

Perhaps there is a different character other than the ^ and $ at the beginning and end of the regular expression I need to use.


Much thanks ...
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 40568602
Ordinarily you can use multi-line to alter the behavior of ^ and $ in a regex. HOWEVER, the RegularExpressionValidator has an internal check to see that the match consists of the entire string, not just part of it. Multi-line has no benefit inside of a REV, and truthfully doesn't do anything.

And again, you don't need mult-line here.

e.g.

 Screenshot Markup
0
 

Author Comment

by:David Bach
ID: 40568737
Hi kaufmed;

Perhaps we both missed this. I know I did.

The ValidationExpression in your latest example replaced the quotation mark with &quote;. When I changed my regular expression in the same way all worked as expected.


Much thanks for your patience and diligence, Kaufmed.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

771 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