Write a regular expression that will:

  1. Return true if a string begins with letters between a and f , either upper- or lowercase.

  2. Return true if a string contains a number.

  3. In the string My friend is Betsy Ann Savage , capture the first and last name and display them in reverse, as Savage, Betsy .

  4. Replace Betsy with Elizabeth in the previous string.

  5. In the string 123abcdefg584 , replace all the letters with XXX .

  6. Prompt the user for a string of text, then print true if the string ends in three or more numbers .

  7. Prompt the user for a string of text, then display the first three characters in the string.

  8. Prompt the user for a string of text that includes letters and numbers, then print true if the string does not contain the number 4 or the letter a , or print false if not.

  9. Prompt the user for his first and last name. Display true if the name starts with an uppercase letter followed by lowercase letters. The last name would be similar to the following: Jones, Smith, McFadden, O'Reilly , and Jones-Smith .


Validate an international phone number that is represented as follows :

011 49 762 899 20


Start with a one- or two-character code for a United Kingdom postal district, such as B for Birmingham or RH for Red Hill, followed by a one- or two-digit number to represent a sector within that district. For example, RH1 is Red Hill district, sector 1; CM23 is the Chelmsford district, sector 23; and B1 is Birmingham district, sector 1. Following the district and sector is a space, followed by a digit and two characters, such as 4GJ.

For example: CM23 2QP



CM = Chelmsford district


23 = sector 23


2QP = a particular road.

Create a regular expression to validate a UK postal code as described above.


Validate a credit card number using the Lunh formula.

JavaScript by Example
JavaScript by Example (2nd Edition)
ISBN: 0137054890
EAN: 2147483647
Year: 2003
Pages: 150
Authors: Ellie Quigley

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net