Question

I'm trying to make an input for accepting year since 2000 and fortnight (from 01 to 24) i.e. 200101, 201324, but not like 201325 and beyond my code is This:

X.TextFieldFor("fnPayment")
.FieldLabel("Payment Fortnight")
.Value((Model.fnPayment != null ? Model.fnPayment : ""))
.Note("YYYYFF")
.InputID("fnPayment")
.IDMode(IDMode.Legacy)
.Plugins(X.InputMask()
    .Mask("AABCPQ")
    .UnmaskOnBlur(true)
    .ClearWhenInvalid(true)
    .InvalidMaskText("Format must be YYYYQQ, where YYYY refers a year and QQ to fortnight. For example: 201401, 201424")
    .MaskSymbols(ls=> {
        ls.Add(new MaskSymbol { Name = "A", Regex = "[20]", Placeholder = "Y".ToCharArray()[0] });
        ls.Add(new MaskSymbol { Name = "B", Regex = "[012]", Placeholder = "Y".ToCharArray()[0] });
        ls.Add(new MaskSymbol { Name = "C", Regex = "[0-9]", Placeholder = "Y".ToCharArray()[0] });
        ls.Add(new MaskSymbol { Name = "P", Regex = "[012]", Placeholder = "Q".ToCharArray()[0] });
        ls.Add(new MaskSymbol { Name = "Q", Regex = "[0-9]", Placeholder = "Q".ToCharArray()[0] });
    })
)
.ID("fnPaymentContainer")

While I was testing I found the only way to do this was accepting any number from 01 to 29 but after 24 would be invalid and I'm trying to limit users errors.

¿Any Ideas? Any help will be great.

Thanks is advanced.

Was it helpful?

Solution

I can suggest the following.

@(Html.X().TextField()
    .Plugins(
        Html.X().InputMask()
            .Mask("ABCCDE")
            .MaskSymbols(ms =>
                {
                    ms.Add(new MaskSymbol() { Name="A", Placeholder='Y', Regex="2" });
                    ms.Add(new MaskSymbol() { Name="B", Placeholder='Y', Regex="0" });
                    ms.Add(new MaskSymbol() { Name="C", Placeholder='Y', Regex="\\d" });
                    ms.Add(new MaskSymbol() { Name="D", Placeholder='Q', Regex="[0-2]" });
                    ms.Add(new MaskSymbol() { Name="E", Placeholder='Q', Regex="[0-4]" });
                }
            )
    )
)

The only problem - it allows to enter "00" at the end. The second character depends on the first one. Unfortunately, there is no functionality to handle such a case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top