This is a migrated thread and some comments may be shown as answers.

Regular Expression Validator not working in Grid Popup

9 Answers 945 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 23 Nov 2012, 11:20 AM
Hello!

 I habe a problem in the Kendo Grid with the validation via regular expression annotation from mVC

My model has a property Email with following definition:
[RegularExpression(@"([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9\-]{0,62}[a-zA-Z0-9]{1})|[a-zA-Z])\.)+[a-zA-Z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)", ErrorMessage = "Not a valid email")]
[DataType(DataType.EmailAddress)]
 public string Email { get; set; }
When I set the edit style of the grid to inline the regular expression validator is rendered ok:

<input type="text" value="" name="Email" id="Email" data-val-required="Das Feld wird ben&#246;tigt." data-val-regex-pattern="([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9\-]{0,62}[a-zA-Z0-9]{1})|[a-zA-Z])\.)+[a-zA-Z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)" data-val-regex="Not a valid email" data-val="true" class="text-box single-line" data-bind="value:Email">
When the edit mode is set to popup the regular expression is wrong:

<input type="text" value="" name="Email" id="Email" data-val-required="Das Feld wird ben&#246;tigt." data-val-regex-pattern="([w!#$%&'*+-/=?^`{|}~]+.)*[w!#$%&'*+-/=?^`{|}~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]{1})|[a-zA-Z]).)+[a-zA-Z]{2,6})|(d{1,3}.){3}d{1,3}(:d{1,5})?)" data-val-regex="Not a valid email" data-val="true" class="text-box single-line" data-bind="value:Email">
Can someone tell me where is the problem??

Thanks!

Luis

9 Answers, 1 is accepted

Sort by
0
Doug
Top achievements
Rank 1
answered on 28 Nov 2012, 01:36 PM
I'm having the exact same problem with the pop-up grid editor as well.

Doug
0
Doug
Top achievements
Rank 1
answered on 30 Nov 2012, 03:38 PM
Luis,

I found a really bad hack/work-around for this problem. I'm hoping Kendo actually fixes this problem...

First you need to create a custom DataAnnotationAttribute and include javascript to do client side validation for the new annotation. I've attached a sample DataAttribute, a model that uses the annotation and the javascript code needed for it to validate on the client side. The draw back to this, if you also use jquery validation with these annotations, you will need to do the same type of hack to make them work...

Hope this helps. I haven't tested this out too extensively.

Best of luck
Doug
0
Daniel
Telerik team
answered on 03 Dec 2012, 01:29 PM
Hello,

This is a known issue which is logged in our system for further investigation. We will do our best to fix it for one of the next internal builds/official releases. I am sorry for the inconvenience caused.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jan Olsmar
Top achievements
Rank 1
answered on 13 Mar 2013, 06:06 PM
I have some problem regarding regular expression as well.
I use a Listview add it as
[RegularExpression(@"^(((20)((0[0-9])|(1[0-1])))|(([1][^0-8])?\d{2}))((0[1-9])|1[0-2])((0[1-9])|(2[0-9])|(3[01]))[-]?\d{4}$",
ErrorMessage = "Är inget personnummer.")]

In the modell.

This work in other ,not kendo , pages but in the Kendo Listview I get the ErrorMessage whatever I put in the field.

I just dl the 2013 beta and the same result there.

Is this the same issue? Will there be a change in the official release?

Thanks in advance.
0
Daniel
Telerik team
answered on 18 Mar 2013, 03:14 PM
Hello,

Thank you for noticing that the same problem occurs with the ListView. We will fix this for the next official release which is expected later this month.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rusty
Top achievements
Rank 1
answered on 22 May 2014, 09:22 PM
Still having the same issue.  
0
Daniel
Telerik team
answered on 27 May 2014, 09:51 AM
Hello Rusty,

Could you provide a runnable sample that demonstrates the issue with the latest versions?

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rusty
Top achievements
Rank 1
answered on 27 May 2014, 03:03 PM
Daniel,  

I really can’t, because my application is heavily dependent on
database access. 

I can provide you with this information, though:

In my model, I have this expression:

[RegularExpression(@"(?i)[Pp]{1}(?:[Oo0]?[Ss]?[Tt]?)?\s?\.?\s?\b[Oo0](?:[Ff]{2}[Ii]{1}[Cc]{1}[Ee]{1})?\s?\.?\b[Bb](?:[Oo0]{1}[Xx]{1})?|([Pp]{1}[Oo0]{1}\s?[Bb]{1}(?:[Oo0]{1}[Xx]{1})?)", ErrorMessage = "Post Office Boxes not allowed for the Physical Address.  Must be a *PHYSICAL* address.")]
public string cAddress1_Line1 { get; set; }


The following .js libraries are included:

<script type="text/javascript" src="@Url.Content("../../Scripts/jquery-1.9.1.js")"></script>
 <script type="text/javascript" src="@Url.Content("../../Scripts/jquery-1.9.1.min.js")"></script>
 <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.js")"
 <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"
 <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"
  
 <script type="text/jscript" src="@Url.Content("~/Scripts/kendo/2013.2.918/jquery.min.js")"></script>
<script type="text/jscript" src="@Url.Content("~/Scripts/kendo/2013.2.918/kendo.all.min.js")"></script>
<script type="text/jscript" src="@Url.Content("~/Scripts/kendo/2013.2.918/kendo.aspnetmvc.min.js")"></script>
<script type="text/jscript" src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>


The .cshtml page has the following for one of the
textboxes in question (note – there are 4  textboxes for address lines
1-4, all set up the same way in the .cshtml page and the MVC Model class: 
cAddress1_Line1, cAddress1_Line2, etc…)

<td>
@Html.TextBoxFor(model => model.cAddress1_Line1, new { @tabindex = 100, @id = "cAddress1_Line1", @class = "k-textbox", placeholder = "physical address - line 1", @maxlength = "50", @style = "font-size:small; width:90%;" })
</td>



Now, for the regular expression, the results I see in
“Regex Buddy” and “RegexLab.net” are shown Below (and included in the attached
file)


Regex Buddy Results (matches
highlighted by the Regex Buddy program)



However, the results I get in
my application are as follows when the 3 “jquery.validate” files are
included.  This happens (in the file jquery.validate.js) on page load
before anything else displays:


In this case,  I suspect that I’m either loading the wrong
version of jQuery for the validation libraries, or loading them in the wrong
order.

Please advise.

 

If I remove the 3 “jQuery.Validate”  libraries, I
don’t get the error above, but the validation becomes unpredictable:

 

Examples: 

<<unexpected.png>>

I get this (from kendo.aspnetmvc.min.js)
as soon as I “tab out” of my text field, if I include the ‘case – insensitive’
 switch (?i)at the beginning of the regex string.  If I remove that, I get no
error, but traps strings that it shouldn’t.  Note that the text string
“Hippopotamus” was NOT trapped in either of the test benches above:
<<hippo.png>>



Please advise?

 

Thanks –

 

Rusty Cisney


 



 

 

Regex Lab results (matches
highlighted by the RegexLab program):





0
Daniel
Telerik team
answered on 30 May 2014, 11:00 AM
Hi,

I tested the regular expression but it seems to be correctly serialized with the listview. At least on my side the following attribute is outputted which seems to be correct:
data-val-regex-pattern="(?i)[Pp]{1}(?:[Oo0]?[Ss]?[Tt]?)?\s?\.?\s?\b[Oo0](?:[Ff]{2}[Ii]{1}[Cc]{1}[Ee]{1})?\s?\.?\b[Bb](?:[Oo0]{1}[Xx]{1})?|([Pp]{1}[Oo0]{1}\s?[Bb]{1}(?:[Oo0]{1}[Xx]{1})?)"
 
The error when including the jQuery validation scripts indicates that the paths:
<script type="text/javascript" src="@Url.Content("../../Scripts/jquery-1.9.1.js")"></script>
 <script type="text/javascript" src="@Url.Content("../../Scripts/jquery-1.9.1.min.js")"></script>
are not correct and jQuery is not loaded before the jQuery validation script. This error should not matter in this scenario because the Kendo validator is used for the listview and not the jQuery validation.

The error from the kendo.aspnetmvc JavaScript file will be thrown because "(?i)" is not valid for a JavaScript regular expression. The "i" flag needs to be set which currently cannot be done with the RegularExpression attribute. If this is necessary in your scenario then I can suggest to implement a custom attribute that sets flag. Overriding the built-in rule(mvcregex) is another option.

I am not sure if I understand the issue with "Hippopotamus". With the regular expression that you provided it should not be a match in C# or in JavaScript and a validation error seems to be correctly shown in the image that you provided. Could you clarify a bit?

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Luis
Top achievements
Rank 1
Answers by
Doug
Top achievements
Rank 1
Daniel
Telerik team
Jan Olsmar
Top achievements
Rank 1
Rusty
Top achievements
Rank 1
Share this question
or