Skip to content

Commit

Permalink
Merge pull request Suchitra-Sahoo#397 from divyalaldinani/adding-rege…
Browse files Browse the repository at this point in the history
…x-and-changing-UI-contact-page

adding regex(validating mobile, email, name etc) and changing UI in contact page
  • Loading branch information
Suchitra-Sahoo authored May 19, 2024
2 parents 1c3ea86 + 27b4e3d commit 094ca5e
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 15 deletions.
120 changes: 120 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# End of https://mrkandreev.name/snippets/gitignore-generator/#Node
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7972082263222296"
crossorigin="anonymous"></script>

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- <link rel="icon" href="./agriculture-icon-png-2804.png" type="'image/png"> -->
</head>

Expand Down Expand Up @@ -390,7 +392,8 @@ <h2 class="heading">Contact <span>Us!</span></h2>

<textarea name="" id="" cols="30" rows="10" placeholder="Your Message" required></textarea>
<button id="review-btn">Give feedback</button>
<input type="submit" value="Send Message" class="btn" id="contact-btn">
<input type="submit" class="btn" id="contact-btn">


</form>

Expand Down
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"sweetalert": "^2.1.2"
}
}
40 changes: 26 additions & 14 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,38 +117,50 @@ form.addEventListener('submit', (event) => {
const mobileNumber = form.querySelector('input[placeholder="Mobile Number"]').value.trim();
const emailSubject = form.querySelector('input[placeholder="Email Subject"]').value.trim();
const message = form.querySelector('textarea').value.trim();

// const alertBox = document.getElementById('alertBox');
// alertBox.classList.remove('hidden');
// Validation
if (!fullName) {
alert('Please enter your full name.');
const nameRegex = /^[A-Za-z]{2,50}(?: [A-Za-z]{2,50})*$/;
if (!nameRegex.test(fullName)) {
swal({
title: "Custom Styled Alert",
text: "This alert has been styled with custom CSS.",
icon: "info",
button: "Awesome!"
})
swal("Try Again!","Please enter your full name.","warning");
return;
}

const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
alert('Please enter a valid email address.');
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
swal("Try Again!","Please enter a valid email.","warning");
return;
}

const mobilePattern = /^\d+$/;
if (!mobilePattern.test(mobileNumber)) {
alert('Please enter a valid mobile number.');
const mobileRegex = /^\+?(\d{1,3})?[-.\s]?(\(?\d{3,4}\)?[-.\s]?)?\d{3}[-.\s]?\d{3,4}$/;
if (!mobileRegex.test(mobileNumber)) {
swal("Try Again!","Please enter a valid mobile number.","warning");
return;
}

if (!emailSubject) {
alert('Please enter the email subject.');
const emailSubjectRegex = /^[\w\s\p{P}]{10,90}$/;
if (!emailSubjectRegex.test(emailSubject)) {
swal("Try Again!","Please enter email subject.","warning");
return;
}

if (!message) {
alert('Please enter your message.');
swal("Try Again!","Please enter your message.","warning");
return;
}

// form reset
form.reset();
alert('Your message has been sent. Thank you!');
else {
form.reset();
swal("Message received!", "We will get back to you in no time.","success");

}
});


Expand Down
20 changes: 20 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
font-family: "Playfair Display", serif;
}

/* Customizing the title */
.swal-title {
color: #000000 !important; /* Change title color */
}

/* Customizing the text */
.swal-text {
color: #000000 !important; /* Change text color */
}

/* Customizing the button */
.swal-button {
background-color:#053314 !important; /* Change button background color */
color: #ffffff !important; /* Change button text color */
}

/* Customizing the button on hover */
.swal-button:hover {
background-color:#0e4b16 !important; /* Change button hover background color */
}
:root {
--bg-color: #053314;
--second-color: #064b10;
Expand Down

0 comments on commit 094ca5e

Please sign in to comment.