Disabling non alphabet characters while entering the input

<p:inputText id="firstName" placeholder="#{msg.member_name}"
								value="#{memberController.order.firstName}" size="30"
								maxlength="30" widgetVar="firstNameVar" required="true"
								styleClass="#{not component.valid ? 'ui-input-invalid default-input-text' : 'default-input-text'}"
								onkeypress="return disallowNonAlphabethCharacters(event);">
								<p:ajax delay="1000" event="keyup"
									oncomplete="rc([{name: 'component', value: ':primeForm:firstName'},
                        {name: 'widget', value: 'firstNameVar'}]);" />
							</p:inputText>

 

Javascript

<script language="javascript" type="text/javascript">
					// <![CDATA[
					function disallowNonAlphabethCharacters(e) {
						var charCode;
						if (window.event)
							charCode = window.event.keyCode; //for IE
						else
							charCode = e.charCode; //for firefox
						if (charCode == 32) //for &lt;space&gt; symbol
							return true;
						if (charCode == 286)
							return true;
						if (charCode == 287)
							return true;
						if (charCode == 220)
							return true;
						if (charCode == 252)
							return true;
						if (charCode == 350)
							return true;
						if (charCode == 351)
							return true;
						if (charCode == 304)
							return true;
						if (charCode == 105)
							return true;
						if (charCode == 305)
							return true;
						if (charCode == 73)
							return true;
						if (charCode == 214)
							return true;
						if (charCode == 246)
							return true;
						if (charCode == 199)
							return true;
						if (charCode == 231)
							return true;
						if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
							return false;
						if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
							return false;
						if (charCode > 122) //for characters beyond 'z' in ASCII Table
							return false;
						return true;
						// console.log(charCode);
						// // console.log(e);

						// 					        231
					}
					// ]]>
				</script>

Leave a Reply

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