Link to home
Start Free TrialLog in
Avatar of jedistar
jedistarFlag for Singapore

asked on

Regex to look for vbCrLF (carriage) or tabs

Hi,

Currently i have:

Regex.Match(str, "^[\w\s]+$").Success

But if the user hits enter on the multiline textbox
it causes failure to regex

How should i change
Avatar of Sammy
Sammy
Flag of Canada image

Jedistar,
I am not good in regex myself but there is a tool I use for all my asp.net apps
its called regex builder and you can download it and use it for free from
http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=9e33c395-8275-4906-8a09-0bff41fdc1d6

Good luck
try

"^[\w\s\n\t]+$"
Avatar of jedistar

ASKER

i need to disallow \n\t
i think u made it such that it allows \n\t
Avatar of nurbek
nurbek

you may use replace function

str = Replace(str,vbCrlf," ")

what do you mean by dissallowing \n\t? (remove them?)

do not the syntax in asp.net
it is in asp
it finds \n\r\t and replaces with white space

     Set objRegExpr = New regexp
     objRegExpr.Pattern = "[\n\t\r]"
     objRegExpr.Global = true
     objRegExpr.IgnoreCase = true
     newStr = objRegExpr.Replace(str," ")
     Set objRegExpr = Nothing
     Response.Write(newStr)
do not know the syntax in asp.net :(
You can use a RegularExpressionValidator like this.

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Tab or CR is not allowed" ControlToValidate="TextBox1" ValidationExpression="[^\t\n]*"></asp:RegularExpressionValidator>
no no im displaying from db
Sorry! I'm lost.  Can you tell me more about what you want to achieve and show more of your code?
<%# DataBinder.Eval(Container.DataItem, "message") %>                 -> C# code in .aspx

the above message has new line codes inside but when i display it
it comes up as 1 line, how do i get it to display the proper new lines
ASKER CERTIFIED SOLUTION
Avatar of nurbek
nurbek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial