Index: applications/editors/josm/plugins/utilsplugin2/build.xml
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 29239)
+++ applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 29241)
@@ -31,5 +31,5 @@
 
     <!-- enter the SVN commit message -->
-    <property name="commit.message" value="Utilsplugin2: improved pasting tags: paste from JOSM, support JSON format"/>
+    <property name="commit.message" value="Utilsplugin2: validation for pasting tags"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     <property name="plugin.main.version" value="4980"/>
Index: applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteTagsExtendedAction.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteTagsExtendedAction.java	(revision 29239)
+++ applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteTagsExtendedAction.java	(revision 29241)
@@ -48,5 +48,5 @@
             }
         } else { // Paste tags from arbitrary text
-            Map<String, String> tags = TextTagParser.readTagsFromText(buf);
+            Map<String, String> tags = TextTagParser.getTagsFromText(buf);
             if (tags==null) return;
             String v;
Index: applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/helper/TextTagParser.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/helper/TextTagParser.java	(revision 29239)
+++ applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/helper/TextTagParser.java	(revision 29241)
@@ -5,4 +5,10 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import javax.swing.JOptionPane;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.io.XmlWriter;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
 
 public class TextTagParser {
@@ -163,4 +169,9 @@
     }
  
+    public static Map<String,String> getTagsFromText(String buf) {
+        Map<String,String> tags = readTagsFromText(buf);
+        return validateTags(tags) ? tags : null;
+    }
+    
     public static Map<String,String> readTagsFromText(String buf) {
         Map<String,String> tags;
@@ -191,11 +202,50 @@
         // a 1 "b" 2 c=3 d 4 e "5"
         TextTagParser parser = new TextTagParser(buf);
-        System.out.println("free");
         tags = parser.getFreeParsedTags();
         return tags;
-
-    }
-
-
-    
+    }
+
+    private static boolean validateTags(Map<String, String> tags) {
+        String value;
+        int r;
+        if (tags.size()>30) {
+            r=warning(tr("There was {0} tags found in the buffer, it is suspicious!",tags.size()), "", "toomanytags");
+            if (r==2) return false; if (r==3) return true;
+        }
+        for (String key: tags.keySet()) {
+            value = tags.get(key);
+            if (key.length()>50) {
+                r = warning(tr("Key is too long:"), key+"="+value, "keytoolong");
+                if (r==2) return false; if (r==3) return true;
+            }
+            if (!key.matches("[a-zA-Z:_]*")) {
+                r = warning(tr("Suspiciouns characters in tag:"), key, "keydoesnotmatch");
+                if (r==2) return false; if (r==3) return true;
+            }
+            if (value.length()>255) {
+                r= warning(tr("Value too long (max 255 characters):"), value, "valuetoolong");
+                if (r==2) return false; if (r==3) return true;
+            }
+        }
+        return true;
+    }
+    
+    private static int warning(String text, String data, String code) {
+        ExtendedDialog ed = new ExtendedDialog(
+                    Main.parent,
+                    tr("Do you want to paste these tags?"),
+                    new String[]{tr("Ok"), tr("Cancel"), tr("Ingore warnings")});
+        ed.setButtonIcons(new String[]{"ok.png", "cancel.png", "pastetags.png"});
+        ed.setContent("<html><b>"+text + "</b><br/><br/> <div width=\"300px\">"+XmlWriter.encode(data,true)+"</html>");
+        ed.setDefaultButton(2);
+        ed.setCancelButton(2);
+        ed.setIcon(JOptionPane.WARNING_MESSAGE);
+        ed.toggleEnable(code);
+        ed.showDialog();
+        Object o = ed.getValue();
+        if (o instanceof Integer) 
+            return ((Integer)o).intValue(); 
+        else 
+            return 2;
+    }
 }
