-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunremovable-postifx.html
More file actions
57 lines (52 loc) · 1.72 KB
/
unremovable-postifx.html
File metadata and controls
57 lines (52 loc) · 1.72 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Material Design for Bootstrap</title>
<!-- MDB icon -->
<link rel="icon" href="img/mdb-favicon.ico" type="image/x-icon" />
<!-- Font Awesome -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
<!-- Google Fonts Roboto -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap"
/>
<!-- MDB -->
<link rel="stylesheet" href="css/mdb.min.css" />
</head>
<body>
<!-- Start your project here-->
<div class="container d-flex justify-content-center mt-5">
<div class="form-outline" style="width: 22rem;">
<input id="postfix" value="$" type="text" id="form2" class="form-control" />
<label class="form-label" for="form2">Enter the amount</label>
</div>
</div>
<!-- End your project here-->
<!-- MDB -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Custom scripts -->
<script type="text/javascript">
const input2 = document.getElementById('postfix');
input2.addEventListener('input', (e) => {
const {
value
} = e.target;
const len = value.length;
const dolarIndex = value.indexOf('$');
const number = value.substring(0, len - 1);
console.log(dolarIndex === -1);
if (dolarIndex !== len - 1 || dolarIndex === -1 || isNaN(number)) {
e.target.value = '$';
e.target.setSelectionRange(dolarIndex, dolarIndex);
}
});
</script>
</body>
</html>