SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Special Characters

    Hello

    Anyone know what's wrong with my code?

    Code:
    function verify(){
    	for  (var i=1; i<5 ;i++){	
    		var valor= "title"+i;
    		alert(valor);
    		var el=document.getElementById(valor);
    		var re=/^[a-zA-Z0-9 ]+$/;
    		if(!re.test(el.value)) 
    		{
    			alert("Remove special characters!");
    			document.getElementById(valor).value="";
    		}
    }
    }
    Thanks!

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fantastic5 View Post
    Hello

    Anyone know what's wrong with my code?

    Code:
    function verify(){
    	for  (var i=1; i<5 ;i++){	
    		var valor= "title"+i;
    		alert(valor);
    		var el=document.getElementById(valor);
    		var re=/^[a-zA-Z0-9 ]+$/;
    		if(!re.test(el.value)) 
    		{
    			alert("Remove special characters!");
    			document.getElementById(valor).value="";
    		}
    }
    }
    Thanks!
    Have you tried jshint or jslint?
    What are you expecting from your codes?
    Quality codes are optimized and tested...
    Click here for inspiration..

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying another option:

    I want verify the input not empty with this (with array):

    Code:
    function verificarMovies(){
    	var contador = 0;
    for (var i=1; i<=30;i++){	
    		if(document.getElementById("tituloep"+i).value!=""){
    			var count = new Array();
    			count [i] = "tituloep"+i;
    			contador++;
    		}
    }
    }
    and after, verify if input with text respect this regular expression: /^[a-zA-Z0-9 ]+$/

    Thanks!

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved! Thanks.


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
  •