www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Restrict the currency symbol from input field

  1. #1
    Join Date
    Oct 2013
    Posts
    2

    resolved [RESOLVED] Restrict the currency symbol from input field

    Hi all,

    I have searched everywhere and can't seem to find a solution to restricting the use of a currency symbol ($) in a certain form text input field..

    I know this can be achieved by allowing numbers only, but I want the user to be able to insert all characters except the currency symbol. I run a classifieds website which automatically prints the currency symbol on the ads from various categories, and it's becoming a pain having to go through ads on a daily basis to remove additional currency symbols that the users have entered manually.

    Any help with this is greatly appreciated.

    Cheers, Sam

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="UTF-8" />
    	<script>
    		function check()
    		{
    			var elem = document.getElementById('text');
    			var usrInp = elem.value;
    			var regExp = /\$/;
    			
    			if (usrInp.search(regExp) != -1)
    			{
    				alert("Sorry but '$' character is not allowed, please try again!!");
    				elem.value = "";
    				elem.focus();
    				return;
    			}
    			return;
    		}
    	</script>
    </head>
    <body>
    	<input id="text" type="text" />
    	<input type="button" value="check" onclick="check()"/>
    </body>
    </html>
    Last edited by tech_soul8; 10-18-2013 at 05:10 AM.

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    or this

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" />
    <title>123</title>
    <style>
    body, #text{text-align:center;}
    body{padding-top:200px;}
    </style>
    <script>
    window.onload=function(){
    var elem=document.getElementById('text');
    elem.onfocus=elem.onblur=elem.onkeyup=function(){
    val=this.value,re=/\$/g;
    if(re.test(val)){this.value=val.replace(re,'');}
    }
    elem.focus();
    }
    </script>
    </head>
    <body>
    <input id="text" type="text" />
    </body>
    </html>

  4. #4
    Join Date
    Oct 2013
    Posts
    2
    Perfect! Thanks for the prompt responses tech_soul8 & Padonak.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles