Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form validation object and identifier error!

    Hi there

    Pls I was wandering if anyone can help pls I have to authenticate a page where the user is expected to enter a unique 10 character pin consisting of numbers and letters only in fact among its xters it should have at least 3 digits and at least 5 captial letters , mixed in any order.otherwise it is not valid.

    I am just learning javascript so I am just trying to get to crips with the syntax and apply logic to the problem as well....any way

    and was wandering if someone could pls have another look to spot the problem ...The errors (I get ) and the lines are below the code...(with ----------beside the javascript line)

    <Script Language=JavaScript>
    var =userPIN; --------------------
    var = PIN;

    function validatePIN(PIN){

    isPIN = PIN.value;
    nChar = isPIN.length;
    isValid = true;
    if (nChar < 10)
    {
    alert('Input your PIN')
    isValid = false;
    }
    if (isValid)
    {
    testVal = /[0-9]{3}[A-Z]{5}[0-9]{2}/.test(isPIN);
    if (!testVal || nChar != 10){alert('Invalid PIN format');isValid = false}
    }
    if (!isValid)
    {
    PIN.value = "";
    PIN.focus();
    }
    if (isValid){document.forms['Form1'].submit()}
    }

    </Script>
    </Head>
    <Body>
    <Form name='Form1' method='post' action=''>
    PIN: <input type=text name='userPIN' size=12><br><br>
    <input type=button value="Submit" onclick="validatePIN(this.form.userPIN)">-------------
    </Form>

    1.The errors generated is it expectes an identiier on the line ( var= userPIN

    2. Expected object (<input type=button value="Submit" onclick="validatePIN(this.form.userPIN)

    3.. as the present captures 3 numbers , 5 Capital letters and 2 numbers if I I replace
    testVal = /[0-9]{3}[A-Z]{5}[0-9]{2}/.test(isPIN); WITH

    testVal = /[0-9]{3}[A-Z]{5}/.test(isPIN);

    can this capture at least 3 digits and at least 5 captial letters , mixed in any order (the mixed in any order is what is confusing pls


    Pls can anyone help me out pls? I would be grateful for this help.

    Many Thanks in reply.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Welcome to the Coding Forums

    You posted this in the wrong place, if you would have read this: *** WARNING: Questions posted here will be deleted! *** on top of the forum, you would see that.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>50154</title>
    	</head>
    	<body>
    		<form method="post" action="" onsubmit="return validatePIN()">
    			<fieldset>
    				<div>
    					<label for="userPIN">PIN:</label>
    					<input id="userPIN" name="userPIN" type="text" size="10" maxlength="10">
    				</div>
    				<input type="submit">
    			</fieldset>
    		</form>
    		<script type="text/javascript">
    			function validatePIN()
    			{
    				var userPIN = document.getElementById("userPIN");
    				var isValid = true;
    
    				if (userPIN.value.length != 10)
    				{
    					alert('Input your PIN');
    					isValid = false;
    				}
    
    				if (isValid)
    				{
    					testVal = /[0-9]{3}[a-zA-Z]{5}[0-9]{2}/.test(userPIN.value);
    					if (!testVal)
    					{
    						alert('Invalid PIN format');
    						isValid = false;
    					}
    				}
    
    				if (!isValid)
    				{
    					userPIN.value = "";
    					userPIN.focus();
    					return false;
    				}
    
    				return true;
    			}
    		</script>
    	</body>
    </html>
    Ask the forum moderator to move this thread for you.

  • #4
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many Thanks Hemebond


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •