javascript - URL Validation for jQuery paste input -


I am trying to determine if a pasted URL is valid or not. I'm using the Force () function to detect paste events, I'm using a regex which I got for verification (which works and is ok for time). I am also adding some text to tell the user whether this is a valid URL or not.

The only thing that works, when it is inside the bind (URL), the URL is validated. It works when it is kept out, though.

JS:

  Verify the function URL (textwalk) {var urlregex = new RegExp ("^ (http | https | ftp) \: // ([one -zA-Z0-9 \. -.] + (\: [.z- one-zA-Z0-9 \ & amp; amp;% \ $ \ -]) * @) * ((25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9 ]) \ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [ 0-9] {1} | [1-9] | 0) \ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9 ] {2} | [1-9] {1} [0-9] {1} | [1-9] | 0) \ (25 [0-5] | 2 [0 -4] [0-9 ] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [0-9]) | (. [Ek-zA -Z0-9 \ -] \) * [one-zA-Z0-9 \ -] \ (com | edu | gov | integer | mile | net | org | biz | ARPA | info | name | support | air | enclosure | Museums | [a-zA-Z] {2}) (\: [0-9] +) * (/ (| | [one-zA-Z0-9 \? \, \ \ '\\\ + & Amp;% ‧ $ # \ = ~ _ \ -])) * $$); Return urlregex.test (textval); } $ (Document) .ready (function () {// Assign a variable that is in the input box for ur url = $ ("# ent"). Val () // paste this url from anywhere " CSS ("background color", "green"); $ ("# condition") .append ("valid url") (if validateURL (url)) {$ ("# ent"). ); $ ("# Submit"). Attr ('disabled', 'disabled');}});});   

HTML:

  & Lt; input type = "text" name = "ent" id = "ent" & gt; input type = "submit" name = "submit" id = "submit" & gt; & lt ; Div id = "status" & gt; & lt; / div & gt;    

Come You can try:

  $ (document) .ready (function () {function validateURL (textval) {var urlregex = new RegExp ("^ (http | https | ftp) \: // ([a-zA-Z0-9. \ -] + (\: [.a- zA-Z0-9 \ & amp; amp;% \ $ \ -]) * @) * ((25 [ 0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9] | 0) \ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [ 0-9] {1} | [1-9] | 0) \ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0- 9 ] {2} | [1-9] {1} [0-9] {1} | [0-9]) |. ([One-zA-Z0-9 \ -] \) * [zA-Z0-9 \ -] to one [com | edu | gov | integer | mile | net | org | biz | ARPA | info | Name | support | air | enclosure | museum | [a-zA-z] {.? 2}) (\: [0-9] +) * (/ ($ | [one-zA-Z0-9 \ \, \; \\\\\ + & amp; amp;% \ $ # \ = ~ _ \ -] +)) * $ "); Return to return urlregex.test (textval);} // Inputbox Anything that is in / / is that if they are URL $ ("#int") .live ('input paste', function () {var url = $ ("# ent"). Val () , If (validateURL (url)) {$ ("# ent"). CSS ("background color", "green"); $ ("# condition"). Attach ('disabled', 'disabled');}});});   

/ Div>

Comments