TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Prevent only Two Digit After Decimal in JavaScript
Mukesh Kumar
Nov 28
2015
Code
982
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<HTML>
<HEAD>
<script type=
"text/Javascript"
> function checkDec(el)
{
var ex = /^[0-9]+\.?[0-9]*$/;
if
(ex.test(el.value)==
false
)
{
el.value = el.value.substring(0,el.value.length - 1);
}
}
</script>
</HEAD>
<BODY>
<input type=
"text"
id=
""
onkeyup=
"checkDec(this);"
/>
</BODY>
</HTML>
JavaScript
Prevent only Two Digit After Decimal