MVC :: RegularExpressionAttribute Validator Always Returns False?
Nov 17, 2010
I'm using a model which receives some input from a form and has some validation logic attached via attributes. In one case I'm validating personal names, which should include only letters, apostrophes, spaces and dashes, and be no more than 50 chars long. So I have a model property like:
[Code]....
Everything works fine BUT the RegularExpression attribute: if I add it, I always get a validation error, even when what I type in my form is a valid name (e.g. "Foo"). No matter how I modify the regular expression or what I type, I always get an invalid name error.
(For some reason, I cannot see the regex posted correctly here: it is just ^ followed by the Unicode Letter class and []+ including a Unicode letter class, apostrophe, whitespace and dash, ended by dollar: i.e. start of string - any letter - any of the following: letter, apostrophe, whitespace, dash, 1 or more times; end of string).
What I'm doing wrong here?
View 8 Replies
Similar Messages:
Jan 16, 2011
I've an EntityCollection< T > which contains an element but the Contains method returns false.
I've overriden T's 'Equals' method but the 'Contains' method does not call it (while it's said so in documentation).
When I do foreach (T x in coll), x.Equals(element) returns true.
code:
contains(object entCol, object val)
{
var coll = (ICollection<GraphicSockets>)entCol;
var socket = val as GraphicSockets;
foreach (GraphicSockets sock in coll)
socket.Equals(sock); //true for first element, GraphicSocket's Equals function called
coll.Contains(socket);//false, Equals function not called}
the code i'd actually like to use is
private static bool contains(object entCol, object val)
{
Type entColType = typeof(EntityCollection<>).MakeGenericType(val.GetType());
MethodInfo contains = entColType.GetMethod("Contains");
return (bool)contains.Invoke(entCol, new object[] { val });
}
this worked once but stopped when i started using wcf, i wonder how this contains method works.....
View 2 Replies
Jan 24, 2011
I've created a script that adds user data to a database, however, I'd like to check the email entered is unique within the database.
I've already started the query at comm2 but not sure how to progress the script so it tells the user if the email address is already taken.
[code]....
View 9 Replies
Mar 11, 2010
I have a ListView control and under ItemTemplate I have following code:
Code:
<asp:Label ID="Label1" runat="server" Text='<% #MatchCategory(dtCategories.Rows[i]["ID"].ToString().Trim(), Eval("CategoryID").ToString()) %>'></asp:Label>
The MatchCategory method just checks if two values are equal and return true or false. Just below this code I am separately printing dtCategories.Rows[i]["ID"].ToString().Trim() and Eval("CategoryID")
acan see matching values but MatchCategory method always returns false.
View 5 Replies
May 9, 2010
I have configured Forms Authentication in my web config file as below.
Following is my code
[Code]....
The issue is that FormsAuthentication.Authenticate never returns true. This is a very simple website with only two pages and no other code(The code too was copied from MSDN).
[Code]....
View 3 Replies
Apr 14, 2010
Our web application hosted from windows 2003 server, is trying to access a file present in a shared folder of another windows 2003 server. The path for the shared folder is configured in the webconfig file in the below format.
<add key="ReportPath" value="\<Server_Name>Reports"/>
if (!File.Exists(ReportPath))
/ Show the report in a link
This function File.Exists() always returns false and when I try to remove the check, it returned the exception, "Logon failure: unknown username or bad password."
View 2 Replies
Jun 7, 2010
I don't understand how the stored procedure is returning false. It's supposed to continue looping and continue writing rows. Right now it writes the very first row, and then it goes into the If Not AdvanceLinkBanned.Add(banrec) Then and it goes in here, prints the message and exits the sub. Why is it thinking the add returns false? If Not AdvanceLinkBanned.Add(banrec) ? Doesn't this return the id of the new record? Isn't this not zero? Zero would make it false. How can this be false? Isn't it supposed to return the next record created ? Doesn't SELECT SCOPE_IDENTITY() return the value of the record id? How do I test this?
[Code]....
View 2 Replies
Feb 11, 2010
What I'm trying to achieve is to track any change made on a form. I thought DataSet.HasChanges and DataSet.GetChanges would be a good way to accomplish this. However, in the code below DataSet.HasChanges always returns false.
EmployeeDs represents a strongly typed DataSet.how to get changes from the updated row into the new dataSet?
[Code]....
View 2 Replies
Apr 1, 2011
I have a detailsView inside the update panel., and in the detailsView I have a FileUpload Control and a button btn_Upload. In the click event I have written code :
[code]...
View 2 Replies
Feb 15, 2010
I have some trouble using the openid check_authentication. The answer from the openid providers (I tried with google and myopenid) is always: is_valid:false I do already get the openid.sig and openid.identity but when I try to verify my data with the check_authentication call it always returns is_valid:false. What I have done so far (authentication with google openid in this example, but for myopenid it was the same): I redirect the web user from my page to the following: [URL]
(Without the line breaks of course, I put them in this post only to keep it readable. localhost:104/evalgoogle.aspx is my local test environment) I will then get redirected to the google login page where I can sign in and accept that I will login at Localhost. I unchecked the remember checkbox though. After logging in I will get redirected to the return_to page I set and get the following data in the request:
openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.mode=id_res
&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud
&openid.response_nonce=2010-02-12T14%3A46%3A52Z1PDyxBssEN9p5g
&openid.return_to=http%3A%2F%2Flocalhost%3A104%2Fevalgoogle.aspx
&openid.assoc_handle=AOQobUfpVnBFYzFO15z92rru88nWjEnw0u8ethVscpjDwkssp8GjVc0u
&openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to
%2Cresponse_nonce%2Cassoc_handle
&openid.sig=24Hetky5HrNwrY3%2B%2B2vtIGnvmnI%3D
&openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3D{SOMEID}
&openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3D{SOMEID}
(where {SOMEID} is my google id) To verify this signature and google id, I composed a webrequest calling the check_authentication as described in openid.net/specs/openid-authentication-1_1.html#mode_check_authentication. My problem now is that this always returned is_valid:false To eliminate possible problems in my webrequest, I now create just a html form with the data I get back from google like this:
<form method="post" action="<%=Request.Params["openid.op_endpoint"] %>">
<div>
<input type="text" name="openid.mode" value="check_authentication" />
<input type="text" name="openid.assoc_handle" value="<
%=Request.Params["openid.assoc_handle"] %>" />
" />
" />
" />
" />
" />
" />
But this also just yields the is_valid:false
View 1 Replies
Nov 12, 2010
We have just migrated our application from VS 2008 to VS 2010 and our database from Sql server 2005 to 2008. Everything was working great until i tried to login to the site.
As when i try to log into the site, i am surprisingly always getting "FALSE" from Membership.Validateuser (). I goggled it and now i know i am not the alone victim of this irritating bug. Our live site is going to be down...
View 6 Replies
Sep 23, 2010
I have an .aspx page with a couple of textfields. I validate these with jQuery validation plugin when the user clicks the submit button. When the submit button is clicked I also open up a new window, but I only want to open the window if the fields are correctly filled out.How do I stop the window from opening if the fields are not validated?
.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
[code]...
View 1 Replies
Feb 4, 2011
[Code]....
The following setup seems to work fine on the client side, however when I post back and check Page.IsValid, the value is false. I also looked at mevDate.IsValid and it's false. It seems that setting the CultulreName on the MaskedEditExtender is sufficient to get the MaskedEditValidator to emit the correct JavaScript, but on the server side of things it doesn't work. When I flip CultureName to "en-US" everything works as expected.
View 3 Replies
Dec 13, 2010
I would like to check whether a folder exists or not if not create. I'm sure this folder exists, but for some reason I get "false" when I check with "Exists" method.
The only reason I think could be because of the W: drive? I moved this application to production site and even there it returns false.
while I'm type in Windows explorer on my localhost and on the server "W:/Webs/ASPPages/cropper/uploads" it opens this folder. So my localhost and IIS server has W: mapping.
for test I tried to create the folder then it says can't find the path...
userFolderName = @"W:/Webs/ASPPages/cropper/uploads"
//I also tried @"W:WebsASPPagescropperuploads"
//I also tried @"W:WebsASPPagescropperuploads"
//I also tried "W:\Webs\ASPPages\cropper\uploads"
DirectoryInfo dirInfo = new DirectoryInfo(userFolderName);........
View 3 Replies
Apr 16, 2010
I have a page with a (gridview nested within a gridview) in an UpdatePanel (UpdateMode="Conditional"). The nested gridview drops down when you click on an arrow and then you can click on each subgrid rows command field. The gridviews are loaded from the Page_Load event. When I click on the commandfield in the subgrid the Page_Load fires during the partial page postback. From what I have read this is normal with UpdatePanels. But What I don't understand is why both Page.IsPostBack and ScriptManager.GetCurrent(Page).IsInAsyncPostBack test false after I click on the command field in my grid. I need to stop the rebinding of the gridviews ( which causes the subgrid to collapse ) when the command field is clicked.Also: I am using MasterPages and the <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> is located in my mater page form section.Would anyone have any suggestions how to test if a partial page postback is occuringHere is a link to the page source: http://pastebin.org/153774here is a link to the code behind: http://pastebin.org/153781
View 2 Replies
Mar 16, 2011
I'm having trouble with something that is (or should be) fairly straight-forward.
I have a recursive method that traverses an XML file, writing out the element tag names and values.
This is a snippet from the XML file:
[code]
<root>
<all_companies>
<company_group company_group_ID_attr="1">
<company_group_name>Cleaning</company_group_name>
<company_group_ID>1</company_group_ID>
<company company_ID_attr="2">
<name>Bloomburg</name>
<company_ID>2</company_ID>
<Address>blah blah blah</Address>
<employee_refs>
<employee_ref>4</employee_ref>
</employee_refs>
</company>
<company company_ID_attr="4">
<name>Morris</name>
<company_ID>4</company_ID>
<Address>blah blah blah</Address>
<employee_refs>
<employee_ref>3</employee_ref>
<employee_ref>1</employee_ref>
</employee_refs>
</company>
<company company_ID_attr="7">
<name>Ajax</name>
<company_ID>7</company_ID>
<Address>blah blah blah</Address>
<employee_refs>
<employee_ref>4</employee_ref>
<employee_ref>2</employee_ref>
</employee_refs>
</company>
</company_group>
</all_companies>
</root>
[/code]
I use the following XPath expression to access the first <company group> tag:
"root[1]/all_companies[1]/company_group[1]"
On the first call to the recursive method ("swrite_for_select_certain_stuff"),I see with the debugger that I reach the <company_group_name> tag. A recursive call at that point takes me to the text node within the tag ("Cleaning"), but it is a text type node (not an element), so it returns without writing anything to the output stream.
On return from that second call, things go wrong. The Iterator within the while loop returns false for the MoveNext method, when it should have moved to the <company_group_ID> tag (or so I think it should).
Am I missing something here?
OS is Win XP, and .NET is version 4.0.
My code is as follows:
[Code]....
View 1 Replies
Mar 25, 2011
I got custom attributes to work on the server and client, now I want to DRY things up just a little more. How do you override the pattern for RegularExpressionAttribute to include the DisplayName?
Right now I am like this:
[Code]....
Which results in:
[Code]....
View 1 Replies
Jan 25, 2010
If I decorate my model with a regular expression + localized string resource, and the ErrorMessageResourceName does not resolve to something on the object, the following things happen:
The regular expression is ignored altogether from a validation perspectiveNo error messages are raised in the MVC application.I would love it if the framework floated an exception in this instance because exclusion of this rule could have far reaching implications.The following is a modification to the ChangePasswordModel.NewPassword property in the stock MVC 2 RC1 project that exhibits the behavior. Note that while the MyResources does exist in my project, the EMResourceName does not exist on it.
[Code]....
[RegularExpression(@"^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$", ErrorMessageResourceType = typeof(MyResources), ErrorMessageResourceName = "InvalidPasswordMessage2")]
View 3 Replies
Mar 25, 2010
I have a regularexpression validator which validates a valid email. I have two buttons on my form. Submit and undo.On undo, we are reverting the page state to defaultsubmit has it validationgroup set while undo doesnot have any validationgroup and CausesValidation="false".Now when i navigate to page and enter invalid emailaddress,i directly click undo. the validator fires and stops my page from posting.however if i press tab and navigate to other control and then click undo,the validator shows error message but posts back and furthur proessing is done
View 3 Replies
Dec 13, 2010
I have a validator on a textbox that validates against a list to ensure that the user doesn't input the same name. When testing it, if I type in the same name including the same case structure, it returns an error. If I change one letter to a different case, it doesn't return an error but rather my SQL server returns a duplicate error. How do I change the server-side validator so that it picks up duplicate names regardless of case?
View 4 Replies
Dec 31, 2010
I using RangeValidator (0-10)gularExpressionValidator for text box ,Iam using regx for validate numeric characters
But if i enter charcters it will fire both RangeValidator and regx validator eventhoug i am enterd character,
i want to fire both validators seperatly
Here is my code
[code]...
View 8 Replies
Oct 27, 2010
I have a requirement of converting existing english form to multi lingual form.I am currently converting english form to spanish form.
Everything works except the date formats.
The range validator is not working in a spanish form but works in a english form.
I have set the maximum and minimum value in page load as below in the english form
Heres how i have set the values
[code]...
View 6 Replies
Mar 1, 2010
When it comes to field validation, when I use a Compare Validator to make sure a date is a date or a numeric field has a number, I must also use a Required Field Validator to make sure there is something actually enetered. In other words, the Compare Validator allows a blank value even though a blank is not a date or number or whatever.
Is using both a Required Field Validator and a Compare Validator the way to do this or is there some way to make the Compare Validator also require input of some kind?
View 3 Replies
Jul 6, 2010
I have a validator callout extender that works, it shows the callout box. But, it does a postback. It didn't do a post back the first time I clicked the button but it did for subsequent times. I read on the AJAX site that a custom validator must be used with this for it to work. I'm currently using this with a required field and regular expression validator. It works, the callout appears, but it doesn't work every time with out the post back.I posted this to see if there is a way to get this to work with a required field and regular expression validator, with out using a custom validator. I'm using the newest release of the toolkit, so I thought the documentation may be old, since the callout is appearing.
View 8 Replies
Dec 17, 2010
I created my custom validator in one project, something like that:
[Code]....
he composite control in another project. I added a reference of the custom validator project to the composite control project. I have a textbox in a composite control and I would like to validate this textbox by the composite control I created. But how can I do that? How can I create the custom validator instance that is linked to the custom validator I created?
View 1 Replies