Solved

Reqular Expression With Carriage Returns

Posted on 2015-01-24
10
84 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

737 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