JavaScript Regular Expression Test Web page

Source: Internet
Author: User
Tags regular expression
JavaScript Regular Expression Test Web page
How do you normally test regular expressions? Write directly in a large section of code, then wait for the program to run there, and then display the results with alert? Or do you write a page temporarily and throw it away after the test is done?

You can try my this page, although it is very rough, but the test regular expression is enough:)

One, Description:
1. My intention is communication technology. I have a very good level of food. As a result, there are deficiencies in the code that is posted.
2. Code can be arbitrarily modified. If you feel that you have modified the code better than mine, can post it, I am very grateful.
3. I'm not very familiar with JavaScript specifications. My experience comes from the development. Therefore, if you have a better view of it, I would like to thank you for your offer.

Second, test cases:

1. Check to see if there are any non-numeric characters in the string:
Test Regex:d
Test Regex Flags:g
Test string:1234g56t78

2. Check if there are characters in the string that are not 0-9, A~z, A-Z, _:
Test Regex:w
Test Regex Flags:g
Test String:i ' m a pig! Yes I ' m!

3. Match the real number in the string:

Test regex: ([d]+]). ([d]+)
Test Regex Flags:g
Test string:float1234.58.723c65.183

Third, the program code:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<HTML>
<HEAD>
<title>javascript Regex Test Page</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<SCRIPT>
/**
* method to test the regular expression function
* @param method of receiving regular expression classes
*/
function Check (method)
{
Converts the flags of the regular expressions entered by the user to lowercase
Form1.flags.value = Form1.flags.value.toLowerCase ();

If it contains characters that are not G, I, M, Prompt and return
if (Form1.flags.value.search (/[^g|i|m]/g)!=-1)
{
Alert ("Flags only can be G, I, M");
Return
}

Establish regular expressions with user-entered strings and flags
var re = new RegExp (Form1.regex.value, Form1.flags.value);

Gets and displays the string form of the generated regular expression
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.