473,503 Members | 5,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript file name white space validation for a sharepoint attachment

1 New Member
Hi,

I want to validate my file name for whitespace before attaching it to a sharepoint list. Here is my code

Expand|Select|Wrap|Line Numbers
  1. <Script type="text/javascript"> 
  2. function PreSaveAction() 
  3. var attachment; 
  4. var filename=""; 
  5. var fileNameSpecialCharacters = new RegExp("\\s", "g"); 
  6. try { 
  7. attachment = document.getElementById("idAttachmentsTable").getElementsByTagName("span")[0].firstChild; 
  8. filename = attachment.data; 
  9. catch (e) { 
  10. if (fileNameSpecialCharacters.test(filename)) { 
  11. alert("Please remove the special characters from the file attachment name.");
  12. return false; 
  13. else { 
  14. return true; 
  15. </script>
This script is working fine with chrome, FF, But this script is blocking all files in IE 7. This script will work fine if I use it to validate special characters only

Expand|Select|Wrap|Line Numbers
  1. var fileNameSpecialCharacters = new RegExp("[~#%&*{}<>;?/+|\"]");
  2.  
Not sure whats wrong with white space regExp in IE.

Can anybody help?

BR,
Sijo

This reg
Dec 9 '11 #1
1 2920
acoder
16,027 Recognized Expert Moderator MVP
Double check that the file name doesn't somehow have spaces in IE by watching the filename variable.

Post the HTML for the first span in "attachmentsTable".
Dec 11 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
18119
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
4
2442
by: clickon | last post by:
I am building up the validation expression for a RegularExpresionValidator control by retreiving some values from a database and looping through the DataTable to build and adding lots of |...
12
4520
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
7
2607
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
1
1617
by: runway27 | last post by:
i have a register.php and confirmregister.php file. in the first file the user fills a registeration form and in the second page they can review what they entered in the first page and then...
9
9345
by: ashokd001 | last post by:
Hi I am faceing a problem with a space in file name. I want to write a script which will open a file that file contain others file name, among them few file name contain space. >cat checkfile...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.