Javascript trim function example

Javascript trim function example

Javascript trim function program and the screenshot of the output is given below,


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
	function trim(withSpace) {
     	 return withSpace.replace(/^\s+|\s+$/g,"");

	function getInput(){
		var input = document.getElementById("inp").value;
		document.getElementById("out").value = trim(input);

Enter the input : <input type="text" id="inp"> <input type="button" onclick="getInput()" value="Trim"> <br>
output: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="out" >








Thanks for reading this post………..!!!

815 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.