Skip to content

Commit c477ea0

Browse files
authored
Create form.py
1 parent 404612d commit c477ea0

File tree

1 file changed

+103
-0
lines changed
  • GUIScripts/Registration Form Web App

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from pywebio.input import *
2+
from pywebio.output import *
3+
from pywebio.session import *
4+
import re
5+
6+
# For checking Email, whether Valid or not.
7+
regex = '^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$'
8+
9+
# For checking Phone Number, whether Valid or
10+
# not.
11+
Pattern = re.compile("(0/91)?[6-9][0-9]{9}")
12+
13+
# For Checking URL, whether valid or not
14+
regex_1 = ("((http|https)://)(www.)?" +
15+
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
16+
"{2,256}\\.[a-z]" +
17+
"{2,6}\\b([-a-zA-Z0-9@:%" +
18+
"._\\+~#?&//=]*)")
19+
Pattern_1 = re.compile(regex_1)
20+
21+
22+
def check_form(data):
23+
24+
# for checking Name
25+
if data['name'].isdigit():
26+
return ('name', 'Invalid name!')
27+
28+
# for checking UserName
29+
if data['username'].isdigit():
30+
return ('username', 'Invalid username!')
31+
32+
# for checking Age
33+
if data['age'] <= 0:
34+
return ('age', 'Invalid age!')
35+
36+
# for checking Email
37+
if not (re.search(regex, data['email'])):
38+
return ('email', 'Invalid email!')
39+
40+
# for checking Phone Number
41+
if not (Pattern.match(str(data['phone']))) or len(str(data['phone'])) != 10:
42+
return ('phone', 'Invalid phone!')
43+
44+
# for checking Website URL
45+
if not re.search(Pattern_1, data['website']):
46+
return ('website', 'Invalid URL!')
47+
48+
# for matching Passwords
49+
if data['pass'] != data['passes']:
50+
return ('passes', "Please make sure your passwords match")
51+
52+
53+
# Taking input from the user
54+
data = input_group("Fill out the form:", [
55+
input('Username', name='username', type=TEXT,
56+
required=True, PlaceHolder="@username"),
57+
58+
input('Password', name='pass', type=PASSWORD,
59+
required=True, PlaceHolder="Password"),
60+
61+
input('Confirm Password', name='passes', type=PASSWORD,
62+
required=True, PlaceHolder="Confirm Password"),
63+
64+
input('Name', name='name', type=TEXT, required=True,
65+
PlaceHolder="name"),
66+
67+
input('Phone', name='phone', type=NUMBER,
68+
required=True, PlaceHolder="12345"),
69+
70+
input('Email', name='email', type=TEXT,
71+
required=True, PlaceHolder="[email protected]"),
72+
73+
input('Age', name='age', type=NUMBER, required=True,
74+
PlaceHolder="age"),
75+
76+
input('Portfolio website', name='website', type=TEXT,
77+
required=True, PlaceHolder="www.XYZ.com")
78+
79+
], validate=check_form, cancelable=True)
80+
81+
# Create a radio button
82+
gender = radio("Gender", options=['Male', 'Female'], required=True)
83+
84+
# Create a skills markdown
85+
skills = select("Tech Stack", options=[
86+
'C Programming', 'Python', 'Web Development', 'Android Development'],
87+
required=True)
88+
89+
# Create a textarea
90+
text = textarea("Comments/Questions", rows=3,
91+
placeholder="Write something...", required=True)
92+
93+
# Create a checkbox
94+
agree = checkbox("Agreement", options=[
95+
'I agree to terms and conditions'], required=True)
96+
97+
# Display output using popup
98+
popup("Your Details",
99+
f"Username: @{data['username']}\nName: {data['name']}\
100+
\nPhone: {str(data['phone'])}\nEmail: {data['email']}\
101+
\nAge: {str(data['age'])}\nWebsite: {data['website']}\
102+
\nGender: {gender}\nSkill: {skills}\nComments: {text}",
103+
closable=True)

0 commit comments

Comments
 (0)