-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (30 loc) · 1 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$(document).ready(function () {
$('#submit-button').click(function () {
const regexString = $('#regex-input').val();
const testString = $('#test-input').val();
if (!regexString && !testString) {
$('#result').html('Please enter a regular expression and a test string.');
return;
}
if (!regexString) {
$('#result').html('Please enter a regular expression.');
return;
}
if (!testString) {
$('#result').html('Please enter a test string.');
return;
}
try {
const regex = new RegExp(regexString);
const result = regex.test(testString);
$('#result').html(result ? 'True' : 'False');
} catch (error) {
$('#result').html('Invalid regular expression.');
}
});
$('#clear-button').click(function () {
$('#regex-input').val('');
$('#test-input').val('');
$('#result').html('');
});
});