Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:35:43+00:00 2026-05-16T10:35:43+00:00

Hoo boy. A weird one I guess! getting input from a form, I want

  • 0

Hoo boy. A weird one I guess!

getting input from a form, I want to make sure there are no western characters, punctuation or numbers before sending it to a php script for creating some xml…

from form name = “a”

$('form').submit(function() {

text = ($(this).serialize());

text = text.substr(2,text.length)

text = text.replace(/[^\u3040-\u30FF^\uFF00-\uFFEF^\u4E00-\u9FAF^\u3400-\u4DBF]/g,'');

—> text goes to php script using .ajax

However, the Japanese is being converted to ASCII before it gets to the regex!

eg. あああ becomes %E3%81%82%E3%81%82%E3%81%82

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:35:43+00:00Added an answer on May 16, 2026 at 10:35 am

    I would swap it around and change the inputs before serializing, like this:

    $('form').submit(function() {
      $(this).find(':text, textarea').val(function(i, v) {
        return v.replace(/[^\u3040-\u30FF^\uFF00-\uFFEF^\u4E00-\u9FAF^\u3400-\u4DBF]/g,'');
      });
      var text = ($(this).serialize());
      //submit form....
    });
    

    This uses .val() to get and replace the old value based on the regex before the serialization (and more importantly, encodeURIComponent() gets called in there).


    Another alternative is to do the regex yourself in the middle of the .serialize() steps, like this:

    $('form').submit(function() {
      var arr = $(this).serialzeArray();
      $.each(arr, function() {
        this.value = this.value.replace(/[^\u3040-\u30FF^\uFF00-\uFFEF^\u4E00-\u9FAF^\u3400-\u4DBF]/g,'');
      });
      var postData = $.param(arr);
    });
    

    .serialize() is really just $.param($(this).serializeArray()) so all we’re doing is splitting it up here, taking the value of the {name:'name',value:'value'} object pairs in the array that .serializeArray() creates and running the regex on each. After that we’re passing the changed array, western-character-less to $.param() to get serialized as a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in a hoo-ha with my boss as I can't shift to using newer
The following code works: String str= test with foo hoo; Pattern pattern = Pattern.compile(foo);
In my small app for Mac OS X I display some info in system
What are books about how to build a natural language parsing program like this:
I made simple procedure just to demonstrate CREATE PROCEDURE `demo`(demo_int int) BEGIN DECLARE minid
Let's say I have some text that has the pattern as shown by the
The values will be in this format 123-123-123-12345 that I would like the preg_match
I came into IOC via Google Guice. And now I've been forced to use
In winforms/C# most all UI Controls have a .Tag tag, so like myButton.Tag =
two questions today, I'm a busy bee and luckily I have an awesome community

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.