Jump to content

[Resolvido] Validar valor decimal


t0ze
 Share

Recommended Posts

Boa tarde pessoal,

É com certeza burrice minha, mas não sei simplesmente o que fazer:

http://jsfiddle.net/SnakeEyes/eu7P9/3/

Não consigo criar um ficheiro .html com esse exemplo.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">

$('.numbersOnly').keyup(function () {
if(($(this).val().split(".")[0]).indexOf("00")>-1){
 $(this).val($(this).val().replace("00","0"));
} else {
 $(this).val($(this).val().replace(/[^0-9\.]/g,''));
}
});​
</script>
<input type="text" id="numbersOnly" value=""/>​

Alguem pode dar uma dica?

Cumps

Link to comment
Share on other sites

<html>
<head>
 <title></title>
 <script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
 <script type="text/javascript">
  $(document).ready(function() {
 $('.numbersOnly').keyup(function (e) {
    if(($(this).val().split(".")[0]).indexOf("00")>-1){
	    $(this).val($(this).val().replace("00","0"));
    } else {
	    $(this).val($(this).val().replace(/[^0-9\.]/g,''));
    }
    if($(this).val().split(".")[2] != null || ($(this).val().split(".")[2]).length ){
	    $(this).val($(this).val().substring(0, $(this).val().lastIndexOf(".")));
 }
 });
 });
 </script>
</head>
<body>
 <input type="text" class="numbersOnly" value="" />​
</body>
</html>

Obrigado KiNgPiTo e yoda.

KiNgPiTo se não fosse o teu post a encaminhar-me era difícil, só com o tutorial que o yoda enviou (e que ajudou e q foi mto útil na definição da função)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.