For another example, if you want to allow a user to enter a phone number in the format: (855)987-678. It is also hard to complete this task by using what you have learnt with the string object.
For example, to solve the first problem, you can write a string pattern as below:
Then supply this string variable to the replace() method of your string object.
A string pattern of regular expression object is written between the forward slash(/pattern/) to inform the browsers that it is regular expression.
You may feel hard to write a pattern right now. In the next pages of Regular Expression topic you learn more things including how to write patterns and use them with the string object methods that you have learnt from the String Object topic.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: