1

I have an angular form like:

<mat-form-field>
    <input
        matInput
        placeholder="Name">
</mat-form-field>

I need to capitalize each word in input. I used following code:

input.value = current.replace(/\b(\w)/g, symbol => symbol.toLocaleUpperCase());

but it doesn't capitalize characters like "ľščťžýáíé..." how can I solve this?

After inserting "abcděf čdef" it returns "AbcděF čDef" (just an example)

2 Answers 2

1

\b is a non word boundary (i.e \b would make a boundary for any any character which doesn't belong to any 1 of [0-9a-zA-Z_])

So those accented word become the boundary for your word..

Instead use this regex

         /(^|\s)[a-z\u00E0-\u00FC]/g
Sign up to request clarification or add additional context in comments.

2 Comments

you sure ?, check this out stackoverflow.com/questions/16573099/…
solved, chceck my answer, it didn't just accept characters after \u00FC
1

SOLVED:

replaced original regex: /\b(\w)/g
with new regex: /(^|\s)[a-z\u00E0-\u170E]/g

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.