JavaScript - only numbers?

Asked By John Millja
03-Oct-05 03:08 PM
can somone give me a javascript function to allow only numbers and not more than 3 digits?

Contains some info  Contains some info

03-Oct-05 03:23 PM
http://www.mattkruse.com/javascript/validations/

Here is the code  Here is the code

03-Oct-05 03:31 PM
<script language="JavaScript" type="text/javascript">
 var frmvalidator = new Validator("myform");
frmvalidator.addValidation("Phone","maxlen=3");
 frmvalidator.addValidation("Phone","numeric");
</script>

Sample using Regex  Sample using Regex

03-Oct-05 03:50 PM
function fnValidate()
		{
			
			var val=document.Form1.txt.value;
			alert(val);
			var re = new RegExp("^[0-9]{3}$");
			if(val.match(re))
			{
			 alert("OK");
			}
			else
			{
			 alert("NOT OK ");
			}

		}
see this  see this
04-Oct-05 05:15 AM
http://sarahk.pcpropertymanager.com/muck/multi-javascript.php
Create New Account
help
validation in javascript white space or blank space validation for dhtml text box in javascript. . . . . . . . . . . . . . . < script language = "JavaScript" > function isSpacesOnly(field) { r = field.value.replace( / \ s / g, "" ) return (r.length = = 0) } < / script > < input type = "text" name = "textfield" onblur = "if(isSpacesOnly(this)){alert('unacceptable ')}" > Another one: < script language = "JavaScript" > function hasWhiteSpace(s) { reWhiteSpace = new RegExp( / ^ \ s+$ / ); / / Check for white space if (reWhiteSpace.test(s)) { alert( "Please Check Your Fields For Spaces" ); return false ; } return true ; } < / script > What you need to do is to trim the string before validation. Trimming a string a space then the trimmed version of that string will be empty. for that use Regex var value = document.getElementById('<% = txtCCode.ClientId %> ').value.replace( / ^ \ s+ | \ s+$ / g, ''); if (window.value.length html xmlns = "http: / / www.w3.org / 1999 / xhtml" > <head id = "Head1" runat = "server" > <title> < / title> <script type = "text / javascript" > function Check ( evt ) { if ( evt . keyCode = = 32 ) { alert ( "Space not allowed" ); return
emailvalidation i want java script for validating email entered by an user. . .help me <script language = JavaScript runat = Server> function test(src) { var emailReg = "^[ \ w-_ \ .]*[ \ w-_ \ .] \ @[ \ w] \ .+[ \ w]+[ \ w]$"; var regex = new RegExp(emailReg); return regex.test(src); } < / script> var emailPat = / ^( \ ".* \ " | [A-Za-z] \ w*)@( \ [ \ d{1, 3}( \ . \ d{1, 3}){3}] | [A-Za HTML document - -> <!- - STEP ONE: Paste this code into the HEAD of your HTML document - -> <HEAD> <SCRIPT LANGUAGE = "JavaScript"> <!- - This script and many more are available free online at - -> <!- - The JavaScript Source!! http
validation for mobile no <script language = "javascript"> function Validate() { var x = document.form1.txtPhone.value; var y = document.form1.txtMobile.value return false; } if (y.charAt(0)! = "9") { alert("it should start with 9 "); return false } } < / script> . . . . i create mobile textbox is txtmobile.text. . .here this txtmobile.text where will i write ValidateBtn_Click" runat = "server" / > < / td> Adapt this snippet - string pattern = @"^ \ d{10} $"; string data = "111111111111"; if (Regex.IsMatch(data, pattern)) { Console.WriteLine("Match"); } else { Console.WriteLine("Not a Match"); } Include a reference In .aspx page write your function and call this function on submit button like this- <script language = "javascript"> function Validate() { var x = document.form1.txtPhone.value; var y = document.form1.txtMobile.value return false; } if (y.charAt(0)! = "9") { alert("it should start with 9 "); return false } } < / script < asp : Button ID = "b" Text = "details" runat = "server" onClientClick = "return Validate()" / > TRY AND LET ME
application help me to validate the numbers, letters and email id's end of post script language = "Javascript"> / * * * DHTML email validation script. Courtesy of SmartWebby.com ( http: / / www.smartwebby.com / dhtml / ) * / function echeck(str) { var at = "@" var return false } if (echeck(emailID.value) = = false){ emailID.value = "" emailID.focus() return false } return true } < / script> check this link http: / / www.smartwebby.com / DHTML / phone_no_validation.asp using System.Text.RegularExpressions; string a-z | 0-9]*( \ .[a-z][a-z | 0-9]*)?)$" ; System.Text.RegularExpressions. Match match = Regex .Match(email, pattern, RegexOptions .IgnoreCase); if (!match.Success) { / / error in address } http: / / social.microsoft.com Validating event of textbox or in Leave event of textbox and make use of the regex classes which are located in the namespace System.Text.RegularExpressions System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][ \ w \ .-]{2, 28}[a-zA-Z0-9]@[a-zA-Z0-9][ \ w
want to give permissions to enter numaric values only. for that wat is the java script. you can use regular expression will allow numeric values from 0-9 Regex = / ^[0-9] \ d*$ / You can use RegEx or below script <SCRIPT language = "JavaScript"> <!- - function IsNumeric(strString) / / check for valid numeric strings { var strValidChars = "0123456789.-"; var strChar; var true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) = = -1) { blnResult = false; } } return blnResult; } / / - -> < / SCRIPT> Such a function can be used as follows to check a field and return an