jedistar
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
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
try
"^[\w\s\n\t]+$"
"^[\w\s\n\t]+$"
ASKER
i need to disallow \n\t
ASKER
i think u made it such that it allows \n\t
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)
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:RegularExpressionVali dator ID="RegularExpressionValid ator1" runat="server" ErrorMessage="Tab or CR is not allowed" ControlToValidate="TextBox 1" ValidationExpression="[^\t \n]*"></as p:RegularE xpressionV alidator>
<asp:RegularExpressionVali
ASKER
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?
ASKER
<%# 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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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