• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 20. The RegExp Object: Working w... > Regular Expressions: Character Class...

Regular Expressions: Character Classes

You also can put a number of characters into a character class. Such a class will match any single character in it. To create a character class, you enclose a number of characters in square brackets. We’ve already seen this example, in which we’re searching for any vowel:

<HTML> 
    <HEAD> 
        <TITLE>Checking for Vowels</TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function checkVowels() 
            { 
                var regexp = /[aeiou]/
					var matches = regexp.exec(document.form1.text1.value)
					if (matches) {
					document.form1.text2.value = "Yes, we got vowels!"
					} else {
					document.form1.text2.value = "Sorry, no vowels!"
					} 
            } 
            //--> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Checking for Vowels</H1> 
        <FORM NAME="form1"> 
            Type some text: 
            <BR> 
            <INPUT TYPE="TEXT" NAME="text1"> 
            <BR> 
            <INPUT TYPE="BUTTON" VALUE="Check for Vowels" ONCLICK="checkVowels()"> 
            <BR> 
            <INPUT TYPE="text" NAME="text2" SIZE="30"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint