In this sample program, we will show you how to count the capital and small letters in a given sentence using JavaScript.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.
My personal website is http://www.jakerpomperada.com
Sample Program Output
Program Listing
<html>
<head>
<title>Count Capital and Small Letters in JavaScript</title>
<style>
body{
font-family:arial;
font-size:15px;
font-weight:bold;
}
</style>
<script language="javascript">
function count_all()
{
if (document.getElementById("str").value == '') {
alert("Textbox is Empty !!! Please provide some string.");
document.getElementById("str").value = "";
document.getElementById("upper_str").value = "";
document.getElementById("lower_str").value = "";
document.getElementById("str").focus();
}
else {
var str1 = document.getElementById("str").value;
var numUpper = str1.length - str1.replace(/[A-Z]/g, '').length;
var numLower = str1.length - str1.replace(/[a-z]/g, '').length;
var result = document.getElementById("upper_str");
var result2 = document.getElementById("lower_str");
result.value = numUpper;
result2.value = numLower;
}
}
function clear_all()
{
document.getElementById("str").value = "";
document.getElementById("upper_str").value = "";
document.getElementById("lower_str").value = "";
document.getElementById("str").focus();
}
</script>
</head>
<body>
<br><br>
<h3>Count Capital and Small Letters in JavaScript</h3>
<br>
Enter a String <input type="text" id="str" name="str" value="" size="30" autofocus/>
<br><br>
<input type="button" name="Submit" value="Count" onclick="javascript:count_all()"
title="Click here to count the capital and small letters."/>
<input type="button" name="Submit" value="Clear" onclick="javascript:clear_all()"
title="Click here to clear the text box."/>
<br><br><br><br>
Number of Capital Letter(s) is <input type="text" id="upper_str" name="upper_str" size="3"/>
<br><br>
Number of Small Letter(s) is <input type="text" id="lower_str" name="lower_str" size="3"/>
</body>
</html>