Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone No Field now only accept numbers rather than alphabet #488

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/Components/shared/InputField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ import PropTypes from "prop-types";
*/
function InputField({
name = "none",
placeholder="",
type="text",
placeholder = "",
type = "text",
value = "",
onChange,
required,
className,
min,
}) {
const handleInputChange = (e) => {
if (type === 'tel') {
const regex = /^[0-9]*$/;
const inputValue = e.target.value;
if (regex.test(inputValue)) {
onChange(e); // Call the passed in onChange function only if the value is numeric
}
} else {
onChange(e);
}
};

if (type === 'textarea') {
return (
Expand All @@ -34,36 +45,32 @@ function InputField({
type={type}
placeholder={placeholder}
value={value}
onChange={onChange}
onChange={handleInputChange}
required={required}
name={name}
/>
);
}
else if (type === 'date') {
} else if (type === 'date') {
return (
<>
<input
className={className}
type={type}
placeholder={placeholder}
value={value}
onChange={onChange}
onChange={handleInputChange}
required={required}
name={name}
min={min}
/>
</>
);
}
else {
} else {
return (
<input
className={className}
type={type}
placeholder={placeholder}
value={value}
onChange={onChange}
onChange={handleInputChange}
required={required}
name={name}
/>
Expand All @@ -84,7 +91,10 @@ InputField.propTypes = {
onChange: PropTypes.func.isRequired,
/** Whether the input field is required. */
required: PropTypes.bool,
className: PropTypes.string
/** CSS class for the input field. */
className: PropTypes.string,
/** Minimum value for the input field (used for date type). */
min: PropTypes.string,
};

InputField.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/user/UserRegistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import InputField from "../../Components/shared/InputField";
import ReactiveButton from "reactive-button";
import custBackgroundImage from "../user/imgs/pngtree-blue-pastel-background-picture-image_1599663.jpg"; // Import your background image
import custBackgroundImage from "../user/imgs/pngtree-blue-pastel-background-picture-image_1599663.jpg";
import { FaEye, FaEyeSlash } from "react-icons/fa6";
import i1 from "../user/imgs/white-dog-pastel-blue-background-3d_89917-269.jpg";
import { login, registration } from "../../utils/Functions/userAuthService";
Expand Down