SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Wollongong, AUS
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .edu only registration?

    hi

    I have a form which already validates via PHP (but it's too complicated to edit).

    I want to restrict an email text field, so that the user must enter a .edu email address. But it could be .edu or .edu.au or whatever. So if the code could just search the string for ".edu" anywhere inside would be good.

    I am clueless when it comes to Javascript, could someone please kindly whip up some code?

    cheers
    pixTower - an interesting and entertaining way of advertising!

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi the following code should help although you should really do this with some sort off server side codeto stop people being able to register with javascript turned off.

    Code:
    <script type="text/javascript" charset="utf-8">			
    	var FormCheck = {
    		Init : function(){
    			//replace 'formname' with your form name
    			document.getElementById('formname').onsubmit = function(){
    				//change 'email' to the name off your email field
    				if(!FormCheck.CheckEmail(document.getElementById('email').value)){
    					alert("email address not valid");
    					return false;
    				}
    			};
    		},
    		CheckEmail : function(email){
    		  var re = new RegExp(/^.*\.edu(\.\D{2})?$/);
    			return email.match(re) ? true : false;
    		}
    	};
    	window.onload = function(){
    		FormCheck.Init();	
    	}
    </script>

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Wollongong, AUS
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, awesome... thankyou so much!

    I had another look at the PHP and with some trial and error managed to get it to work.

    Thanks again mate, made my day
    pixTower - an interesting and entertaining way of advertising!

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem glad it helped you.


Bookmarks

Posting Permissions

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