in reply to Re^9: Onkeyup not working
in thread Onkeyup not working

tho i dont have script problem. the only problem is this regex var emailReg = /^(?!.*_)\w+(\.-?\w+)*@\w+(\.-?\w+)*(\.\w{2,3})/; since it includes things like @ thats why problem comes.

but when i try to remove regex . the script work well with other JavaScript codes

Replies are listed 'Best First'.
Re^11: Onkeyup not working
by frank1 (Monk) on Oct 08, 2023 at 15:25 UTC

    i have been able to fix the problem by doing, wat i always do most of the times if anything goes head paining

    i have removed regex from html and put it in perl script

    my $reg = 'var emailReg = /^(?!.*_)\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})/;';

    and then i just call it in javascript like this

    <script> \$('.keyup-email').keyup(function() { var inputVal = \$(this).val(); $reg if(!emailReg.test(inputVal)) { \$(".edBtn").prop("disabled", true); } else if(inputVal == 'test\@test.com') { \$(".edBtn").prop("disabled", true); }else{ \$(".edBtn").prop("disabled", false); } }); </script>

    And worked, so full script is this

    #!/usr/bin/perl -wT use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $derp = "jone"; my $reg = 'var emailReg = /^(?!.*_)\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\ +w{2,3})/;'; print "Content-type: text/html\n\n"; print <<"HTML"; <!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquer +y.min.js"></script> </head> <body> <input type="text" class="keyup-email text-input" name="7" value=""> <button type="butt +on" id="m1p" class="edBtn"> submit </b> </button> <h3>$derp</h3> <script> \$('.keyup-email').keyup(function() { var inputVal = \$(this).val(); $reg if(!emailReg.test(inputVal)) { \$(".edBtn").prop("disabled", true); } else if(inputVal == 'test\@test.com') { \$(".edBtn").prop("disabled", true); }else{ \$(".edBtn").prop("disabled", false); } }); </script> </body> </html> HTML

    most of the times if javascript gives me hard time i just declare it in perl script then i just call it in html as string. and works

    something which is very simple, and most dont think about it that can fix problem

      "most of the times if javascript gives me hard time i just declare it in perl script then i just call it in html as string. and works
      something which is very simple, and most dont think about it that can fix problem"

      More than once in the thread people have suggested separating your perl code from your HTML/JavaScript/CSS, because this makes life simpler. HTML::Template would be a start, several of the linked tutorials use this. Modern frameworks like Mojolicoius::Lite provide more options, for example templates that allow embedding perl code in a clean and sensible manner, among a saner path for web development.

      enjoy the security nightmare you're building