Error in ValidationExpression when using in XSLT - asp.net

My XSLT shows that there is error in the below line, but i could not figure it out
<asp:RegularExpressionValidator ID="validatorEmail{#id}" runat="server" Display="Dynamic" ControlToValidate="{#id}" ErrorMessage="username#domain.com"
ValidationExpression="^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))#((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$" />
Error Message:
Expected token '}', found ','. ...+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2 -->,<-- }))#((([0-1]?[0-9]{1,2}|25[0-5]|... Forms.xslt
What is wrong with this?

In XSLT { and } are used to inject dynamic values in attribute value templates. You need to double them to escape them in your regular expression:
ValidationExpression="^(([\w-]+\.)+[\w-]+|([a-zA-Z]{{1}}|[\w-]{{2,}}))..."

Related

validation expression in asp.net

I am trying to create a validation expression for my regular expression validator control. I am having trouble understanding how to add things to the validation expression. I need it to accept any input (numbers, characters, any special characters) and limit the input to 200. I have this so far:
<asp:RegularExpressionValidator ID="commentRegularExpressionValidator" runat="server" ErrorMessage="Comment box exceeds 200 characters."
ControlToValidate="TextBoxComments"
ValidationExpression="^[a-zA-Z''-'\s\d ^!##$%^&*()_+=-]{0,200}$"
Text="*"
CssClass="errorMessage"
SetFocusOnError="true"
Display="Dynamic"
ValidationGroup="infoGroup"></asp:RegularExpressionValidator>
When I try to add more special characters to the expression, I start getting errors. Can somebody help clarify the format/structure of adding special characters to this validation expression. Thank you
If you need only to accept any input (numbers, characters, any special characters) and limit the input to 200 then Set only property of Textbox like --> MaxLength="200"
Or if you want to show message then use javascript or Jquery like below function on Keydown event of textbox-->
function CountCharacters() {
var maxSize = 200;
if (document.getElementById('<%= txt_handlinginfo.ClientID %>').value != '') {
var len = document.getElementById('<%= TextBoxComments.ClientID %>').value.length;
if (len > maxSize) {
alert('error message');
return false;
}
}
}
You can use .{1,200} regular expression.
. dot character means any character
{1,200} means match 1 or more character upto max 200 characters.
<asp:RegularExpressionValidator ID="commentRegularExpressionValidator" runat="server"
ErrorMessage="Comment box exceeds 200 characters."
ControlToValidate="TextBoxComments"
ValidationExpression=".{1,200}"
Text="*"
CssClass="errorMessage"
SetFocusOnError="true"
Display="Dynamic"
ValidationGroup="infoGroup">
</asp:RegularExpressionValidator>

RangeValidator doesnt work as expected using specific date

When I try to submit a specific date "20-10-2013" (international format: 2013-10-20"), rangevalidator throws the error message for invalid date
<asp:TextBox ID="txtDataInicial" runat="server" Width="55px"></asp:TextBox>
<asp:RangeValidator ID="rgvDtInicial" runat="server" ControlToValidate="txtDataInicial"
Display="Static" MinimumValue="01/01/1800" MaximumValue="31/12/9999" Type="Date"
ErrorMessage="A data inicial, deve ter o seguinte formato: DD/MM/AAAA"
ValidationGroup="Consultar"></asp:RangeValidator>
<asp:Button ID="btnConsultar" runat="server" Style="width: 150px;" Text="Consultar"
OnClick="btnConsultar_Click" ValidationGroup="Consultar" />
It works for dates like , "19-10-2013", "21-10-2013", "20-10-2014", "20-10-2012".
It just happens when I submit this date!
Does anyone know why?
Dates are culture-depended. Specify your culture declaratively in web.config or in a Page directive, or programatically.
Check this out: http://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.100).aspx
Rangevalidator control front end code
This is the culprit of the error. Make sure the cultureinvariantvalues is set to false.
Ensure assigning the correct minimum & maximum date range at code behind.
This is to standardise our date comparison to culture="en-GB" which use "dd/mm/yyyy" independent of server localization setting. You may use the "en-US" and the format will be "mm-dd-yyyy".
http://chinteongtan.blogspot.com/2014_04_01_archive.html

The server tag is not well formed error in WhereCondition=

I know the error is caused by the <%# Eval("NodeID")%> statement. When I put a literal integer, it works fine. I tried changing the outside double quotes of the WhereCondition to single quotes, and the inside quotes to double quotes, but this throws an exception.
<cms:CMSRepeater ID="subcatPreviewImages" Path= '<%# Eval("NodeAliasPath") + "/%" %>' runat="server" ClassNames="CMS.MenuItem" TransformationName="EcommerceSite.Transformations.EMCategorySmallImagePreview" OrderBy="NodeLevel, NodeOrder, NodeName" MaxRelativeLevel="4" WhereCondition="DocumentMenuItemHideInNavigation='false' AND NodeParentID= <%# Eval("NodeID")%> AND NodeLevel=3" />
You need to build your string inside the databind tag like you did with the NodeAliasPath property:
WhereCondition='<%# "DocumentMenuItemHideInNavigation='false' AND NodeParentID=" + Eval("NodeID") + " AND NodeLevel=3" %>'
If you are having trouble with the mixed ' and " characters, you may want to move the logic that builds the expression into a function in your page:
public string GetWhereCondition(SomeType dataItem) {
return "..." + dataItem.NodeID + "...";
}
And the your tag changes to:
WhereCondition="<%# GetWhereCondition(Container.DataItem) %>"
Disclaimer: function and type names are made up for example only -- please use appropriately named functions and replace my poorly-named ones.

zipcode regular expression validation

I would like to have a regular expression validator for validating zip code. My zip code length varies up to 9 digits. User can enter either 5 or 9. I should valid if he enters 5 digits or 9 digits. Any thing other than that I would like to raise error.
I tried this expression
ValidationExpression="\\d{5}(-\\d{4})?$"
This is my design I am using rad controls
<telerik:RadMaskedTextBox Mask="#####-####" runat="server" ID="txtcontactZipCode"
Width="200px" ValidationGroup="contactValidation">
</telerik:RadMaskedTextBox>
<asp:RequiredFieldValidator runat="server" ID="rqrdcontactZipCode" ValidationGroup="contactValidation" Display="Dynamic"
ForeColor="Red" ControlToValidate="txtcontactZipCode" ErrorMessage="Zip Code is required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexpcontactZipCode" runat="server" ControlToValidate="txtcontactZipCode"
ValidationGroup="contactValidation" Display="Dynamic" ForeColor="Red" ErrorMessage="Should be 5 or 9 Digits"
ValidationExpression="\\d{5}(-\\d{4})?$"></asp:RegularExpressionValidator>
But I am unable to valid if I enter as follows 11111-____
Can some one help me..
The issue is that your regular expression indicates the four digits must exist if you have the dash. Generally that would be okay but since you're using an input mask the dash always exists, even when it's only five digits. Try the following expression.
ValidationExpression="\d{5}-?(\d{4})?$"
You should only use \\ to escape when you're setting it through C# code-behind.
Use this...
ValidationExpression="\d{5}(-\d{4})?$"
If you were setting it through the C# in the background, then you would need \\d because \d would be considered to be a control character...
txtcontactZipCode.ValidationExpression = "\\d{5}(-\\d{4})?$";
This is unless you precede the string with #, in which case it could be done as...
txtcontactZipCode.ValidationExpression = #"\d{5}(-\d{4})?$";
What about :- [0-9]{5}(\-[0-9]{4})?
[0-9] Any number between 0 and 9, {5} = only 5 characters; Altarnativly \d depending on what you find easier to read.
( ) - Create a group
\-[0-9]{4} A Dash followed by 4 numbers
? Optional - Zero or One
Use this method:
public static boolean validateZip( String zip )
{
return zip.matches( "\\d{5}" );
}

How to use webdings character map in asp.net

I want to use webdings characters in .net application.
Does anyone know how to do this.
I tried using :
ASPX:
<asp:Label ID="lblSample" runat="server" Font-Names="Webdings" ></asp:Label>
CODE BEHIND:
lblSample.Text = "0x61"
But it doesn't displaying properly.
As can be seen in any ASCII table, character 0x61 is a lower case a.
You are trying to output the string "0x61" instead of a lower case a.
You should be doing this:
lblSample.Text = "a"

Resources