-1

My html is:

 <input type="text" name="username">

If we write any validation also ,i need the function related stuff to happen in typescript but not java script.

7
  • You mean :<input required pattern=".*\S+.*" title="This field is required"> Commented Jun 1, 2017 at 11:24
  • Check this :stackoverflow.com/questions/39236992/… Commented Jun 1, 2017 at 11:28
  • Yeah i have to apply pattern.Correct.But what if I have to apply to say many text fields that too in different page .Is there a way to apply a pattern to all the text fields once at a time? Commented Jun 1, 2017 at 11:30
  • not possible with HTML but you can go with custom validator in typescript Commented Jun 1, 2017 at 11:32
  • Yes I wanted those validators written in typescript.Can you please give me a code example in typescript? Commented Jun 1, 2017 at 11:39

1 Answer 1

1

The simplest way is to use Regex in whatever implementation you need to filter for leading/trailing whitespace. If you want simple validation, try the HTML5 pattern attribute.

^(?=[A-Za-z0-9])([A-Za-z0-9\s]*)(?<=[A-Za-z0-9])$

https://regex101.com/r/bJCJBv/2

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

Comments

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.