The other issue is that regular expressions don’t deal directly with numbers. That’s because the characters for the digits 0 through 9 occupy consecutive positions in the ASCII and Unicode character tables.You can’t tell a regular expression to “match a number between 1 and 31”, for instance. See Chapter 6 for more details on matching all kinds of numbers with regular expressions.Then I created a variable that contains the result of running the test() function on the phone Number string which will be a boolean that contain either true if the string matches our regular expression or false if it does not.Now let’s jump into the fun part which is discussing the regular expression First we have the starting and ending slashes “/” , the expression then starts with a “^” sign to match with the beginning of the string. Regex class for validate any input string for any specific format.Ninety-nine percent of software applications require data which are entered by users, for example when you want to create an email account (Hotmail, Gmail ...Here I have added a new variable called postal Code to fetch the postal code from the form then created another variable to store the postal code regular expression which we will be discussing in a second.Then I used the test function to test my string against the regular expression and print the result in an alert.
Jul 13, 2005: (reply to korell) The regular expression is created and stored in the memory. After adding this value to the database and dealing with it in another place, for example if you want to send this user an sms message, in this situation your system will try to send a message to this phone number “abcde”, it’s not only a fake phone number it’s something not related even to numbers.So as a software developer you should know that there are two types of users, Also imagine that you have a web application and there is a form to add a new article, this form contains a text box to enter the title of the article which will render as a label when the users will read the article, if one of the users write “Some text” in the field, this will cause a big problem because when the users will open the article instead of seeing the title they will see a link that is maybe a dangerous link.Etc.), you see a form contains a number of fields and each one of these fields has to be filled in with specific data such as Email, Zip code, phone number and a password with specific conditions.As a developer you create a form like this and put a label beside each field to tell the user that you should enter your zip code in this field, but actually not all the users follow the labels and enter what you are waiting for, sometimes one of the users will enter a fake email address or even enter some letters that don’t refer to anything like “abcdef” as Phone number, this mistake will lead to some problems.
Because of this, you have to choose how simple or how accurate you want your regular expression to be.