-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
32 lines (26 loc) · 1.31 KB
/
app.py
File metadata and controls
32 lines (26 loc) · 1.31 KB
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
from flask import Flask, render_template, request, jsonify
import re
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/results', methods=['POST'])
def results():
if request.method == 'POST':
test_string = request.form.get('test_string')
regex_pattern = request.form.get('regex_pattern')
matches = re.findall(regex_pattern, test_string)
num_matches = len(matches)
digit_or_string_count = sum(1 for char in test_string if char.isdigit() or char.isalpha())
return render_template('index.html', test_string=test_string, regex_pattern=regex_pattern,
matches=matches, num_matches=num_matches, digit_or_string_count=digit_or_string_count)
@app.route('/validate-email', methods=['POST'])
def validate_email():
if request.method == 'POST':
email = request.form.get('email')
regex_pattern = r'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'
is_valid = re.match(regex_pattern, email) is not None
result_message = "Valid email address." if is_valid else "Invalid email address."
return render_template('index.html',email= email,is_valid = is_valid,result_message = result_message)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)