Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to resrict user to give only integer value?
Hi to All,
i need a functionality that user has to give only integer in a form field
please tell me if you know
Thanks & Regards
Ramesh K
i need a functionality that user has to give only integer in a form field
please tell me if you know
Thanks & Regards
Ramesh K
You can use struts validator or your own javascript to validate the input value.
use jquery class ="required number"
for example:
<form>
<input type="text" name="phone" class="required number" />
</form>
Provided you should jquery.validate.js to be included
for example:
<form>
<input type="text" name="phone" class="required number" />
</form>
Provided you should jquery.validate.js to be included
You can use the followin Liferay API too
Validator.isNumber("value");
It will return true or false
Regards,
Sandeep
Validator.isNumber("value");
It will return true or false
Regards,
Sandeep
Hi,
You can use this js function also
function checkInt(e) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;
else
return false;
}
you can call this function like that
<input type="text" name="<portlet:namespace />pinCode" value="" onkeypress="return checkInt(event)" />
Regards,
Masroor Khan
You can use this js function also
function checkInt(e) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;
else
return false;
}
you can call this function like that
<input type="text" name="<portlet:namespace />pinCode" value="" onkeypress="return checkInt(event)" />
Regards,
Masroor Khan
Ramesh K:
Hi to All,
i need a functionality that user has to give only integer in a form field
please tell me if you know
Thanks & Regards
Ramesh K
Hello Ramesh,
There are so many possible and working ways are illustrated above, but what I feel personally more comfortale is to achieve it b jquery, as:
<script src="/html/portlet/ext/Search/jquery.validate.js" language="JavaScript"> </script>
<link rel="stylesheet" type="text/css" media="screen" href="/html/portlet/ext/Search/css/screen.css">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#addform").validate({
rules:{
empCode:{required: true,number:true},
firstName:"required",
mobile:{required: true,number:true},
technology:"required",
email: {// compound rule
required: false,
email: true
},
}
});
});
</script>
<style type="text/css">
#form1 { width: 500px; }
#form1 label { width: 250px; }
#form1 label.error, #form1 input.submit { margin-left:}
</style>
In the above code, refer to the line number 8 and 32... The text box of form added in line number 32 is validated by jquery code at line number 8...
You can refer and download the library jquery-validate.js from here...
Hope this will help Ramesh...
Thanks and Regards...