Discussion

151
Views

Restrict Alphabets or Characters, Enter Only Numbers form Keyboard and also restrict the length

If the requirement have only numbers has to be entered from Keyboard or to restrict the entry of Alphabets or Characters from the key board with some specified length, create a control by using the below code.

<%
String maximumChars = tools.getParamValue("maximumChars");
%>
<script>
function validateNumeric(e) {
if (!e) var e = window.event;

if (!e.which) keyPressed = e.keyCode;

else keyPressed = e.which;

if ((keyPressed >= 48 && keyPressed <= 57) || keyPressed == 8 || keyPressed == 9 ) {

keyPressed = keyPressed;

return true;

} else {

keyPressed = 0;

return false;

}

}
</script>

<input size="20" <pega:include name="Attributes" type="Rule-HTML-Property" /> <pega:include name="ClientValidation" />

id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= tools.getParamValue("pega_RLindex") %>"

name="<pega:reference name="$this-name" />"

type=text class="leftJustifyStyle"

value="<pega:reference name="$this-value" />"

maxlength=<%=maximumChars%>
onkeypress="return validateNumeric(event);" size=<%=maximumChars%>>

  • If we want to restrict the Arabic / French / Other Language Characters, Take the key Pressed Value from the Keyboard, Replace with the values and conditions mentioned above.

***Edited by Moderator: Lochan to tag as Developer Knowledge Share***