HTML DOM Input Number min Property
HTML DOM input number min property HTML दस्तावेज़ में type="number" वाले इनपुट फील्ड के min attribute का मान प्राप्त या संशोधित करता है। यह उपयोगकर्ता द्वारा दर्ज की जा सकने वाली न्यूनतम संख्या को परिभाषित करता है।
Syntax
Min मान प्राप्त करना:
numberInputObject.min
Min मान सेट करना:
numberInputObject.min = "number"
उदाहरण
रोल नंबर इनपुट फील्ड जिसमें न्यूनतम 1 और अधिकतम 60 की सीमा है:
<!DOCTYPE html>
<html>
<head>
<style>
html { height: 100%; }
body {
text-align: center;
color: #fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
height: 100%;
}
p { font-weight: 700; font-size: 1.1rem; }
input {
display: block;
width: 35%;
border: 2px solid #fff;
background-color: transparent;
color: #fff;
font-weight: bold;
padding: 8px;
margin: 1rem auto;
}
.btn {
background: #0197F6;
border: none;
height: 2rem;
border-radius: 2px;
width: 35%;
margin: 2rem auto;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
.show { font-size: 1.5rem; font-weight: bold; }
</style>
</head>
<body>
<h1>DOM Input number max/min property Demo</h1>
<p>अपना रोल नंबर दर्ज करें (1 से 60 के बीच)</p>
<input type="number" class="numberInput" min="1" max="60">
<button type="button" onclick="showMySelection()" class="btn">रोल नंबर दिखाएं</button>
<div class="show"></div>
<script>
function showMySelection() {
var numberInput = document.querySelector(".numberInput");
var showMsg = document.querySelector(".show");
console.log(numberInput.min, numberInput.max);
if (numberInput.value === '') {
showMsg.innerHTML = "कृपया मान दर्ज करें!!";
} else {
if (numberInput.value >= 1 && numberInput.value <= 60) {
showMsg.innerHTML = numberInput.value;
} else {
showMsg.innerHTML = "कृपया सही रोल नंबर दर्ज करें!!";
}
}
}
</script>
</body>
</html>
आउटपुट
1 से 60 के बीच कोई रोल नंबर दर्ज करें और "रोल नंबर दिखाएं" बटन पर क्लिक करें। यदि मान सीमा के भीतर है तो वह प्रदर्शित होगा, अन्यथा चेतावनी संदेश दिखेगा।
मुख्य बिंदु
minattribute संख्या इनपुट के लिए न्यूनतम स्वीकार्य मान परिभाषित करता है- ब्राउज़र स्वचालित रूप से मान्य करता है कि दर्ज मान min से कम तो नहीं है
- JavaScript से
input.minproperty द्वारा इसे पढ़/लिख सकते हैं - फॉर्म वैलिडेशन के लिए
minके साथmaxका उपयोग करें - मान string के रूप में सेट किया जाता है लेकिन संख्या के रूप में कार्य करता है