0

I have few queries.

  1. How can I apply MaxLength validation on Email and Telephone just like Single-Line Text field?

enter image description here

I tried to add MaxLength parameter in particular field of form. It is working but I do not want to display error message I want to stop user when user exceed.

  1. I also want to apply only alpha validation on Single-Line Text.

1 Answer 1

5

There's no out of the box control to limit the field length in the way you want, you would either have to create a custom form field or the easier option would be to use some Javascript and CSS to achieve something similar.

Using a similar method to this answer I provided recently, create a CSS class called "limited-length" then add the following JS:

(function ($) {
    $(document).ready(function() {
        $(".limited-length").attr("maxlength", "150");
    });
})($scw);

To restrict the single-line text field to alpha only you can use the "Letter Only" validation option.

enter image description here

If you want to stop the user typing non-alpha characters into the box then you will need to bind a javascript/jquery function, using a similar method as above and restrict the input to alpha keypress only.

Sign up to request clarification or add additional context in comments.

1 Comment

Kam's answer is the best answer to your questions. You can go down the route of creating a Custom Field Type based on the SingleLineText which will allow you to set the max limit per but Textbox but is more complex. If you need a slightly different RegEx to Sitecore's Letters Only, select Custom in the drop down list and enter your own there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.