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

MaskedTextBox Rule does not working

4 Answers 450 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Dongfen
Top achievements
Rank 1
Dongfen asked on 25 Apr 2014, 07:05 PM
I upgrade my kendo UI for MVC to 2014.1.415

I want to add rule to the masked text box.  So I copied the example from this page:
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/maskedtextbox/overview

Here is my view:
--------------------
@{
    ViewBag.Title = "MaskedTextWithRule";
}

<h2>MaskedTextWithRule</h2>


<div class="demo-section">
    <h2>Mask Input </h2>
    <ul id="fieldlist">
        <li>
            <label for="phone_number">Phone number:</label>
            @(Html.Kendo().MaskedTextBox()
                  .Name("phone_number")
                  .Mask("(999) 000-0000")
                  .Value("555 123 4567")
            )
        </li>

        <li>
            @(Html.Kendo().MaskedTextBox()
                  .Name("maskedtextbox")
                  .Rules(rules => {
                      rules.Add("~", "/[+-]/");
                  })
                  .Mask("~0000") //Set a mask with custom rule
            )
        </li>

    </ul>
</div>

<style>
    .demo-section {
        width: 300px;
        margin: 35px auto 50px;
        padding: 30px;
    }

    .demo-section h2 {
        text-transform: uppercase;
        font-size: 1.2em;
        margin-bottom: 10px;
    }

    #fieldlist
    {
        margin:0;
        padding:0;
    }

    #fieldlist li
    {
        list-style:none;
        padding:10px 0;
    }

    #fieldlist label {
        display: inline-block;
        width: 130px;
        margin-right: 5px;
        text-align: right;
    }
</style>

---------------------------------------------------

I compiled the project without problem, but when I run it, I got the following error
--------------------------------------------
Server Error in '/' Application.Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'Kendo.Mvc.UI.Fluent.MaskedTextBoxRulesBuilder.Add(char, string)' has some invalid arguments

Source Error:

Line 22: .Name("maskedtextbox")
Line 23: .Rules(rules => {
Line 24: rules.Add("~", "/[+-]/");
Line 25: })
Line 26: .Mask("~0000") //Set a mask with custom rule


4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 28 Apr 2014, 11:37 AM
Hello Dongfen,

As it is mentioned in the exception message, the Add method accepts only System.Char type for the first parameter. The functionality is incorrectly documented. We will address the issue immediately. Check the updated documentation.
I updated your Telerik points because of the involvement.

Regards,
Georgi Krustev
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
Dongfen
Top achievements
Rank 1
answered on 28 Apr 2014, 05:47 PM
Thank you, Georgi,

I added the text tag, and I can get to the page.
But when I tried to enter + or -, it won't take it.  It only allow 5 digit.


            @(Html.Kendo().MaskedTextBox()
                  .Name("maskedtextbox")
                  .Rules(rules => {
                      rules.Add('~', @<text>"/[+-]/"</text>);
                  })
                  .Mask("~0000") //Set a mask with custom rule
            )



0
Accepted
Georgi Krustev
Telerik team
answered on 29 Apr 2014, 11:16 AM
Hello again Dongfen,


The Add(System.Char,System.Func<System.Object,System.Object>) method should be used when the developer wants to specify a function for the specific rule. When a RegExp is set then you will need to use the first overload. You can refer to the examples into the documentation. For your convenience I prepared a simple test project, which is attached to this page.


Regards,
Georgi Krustev
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
Dongfen
Top achievements
Rank 1
answered on 29 Apr 2014, 07:02 PM
Thanks.
I thought I did the same thing, but it did not work at first.
I found the difference is the single quote for the first Char in Add argument.
Thanks 
Tags
MaskedTextBox
Asked by
Dongfen
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Dongfen
Top achievements
Rank 1
Share this question
or